@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,230 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { Button } from '../../../components/ui/button';
|
|
4
|
+
import { Input } from '../../../components/ui/input';
|
|
5
|
+
import { Label } from '../../../components/ui/label';
|
|
6
|
+
import {
|
|
7
|
+
Select,
|
|
8
|
+
SelectContent,
|
|
9
|
+
SelectItem,
|
|
10
|
+
SelectTrigger,
|
|
11
|
+
SelectValue,
|
|
12
|
+
} from '../../../components/ui/select';
|
|
13
|
+
import {
|
|
14
|
+
Collapsible,
|
|
15
|
+
CollapsibleContent,
|
|
16
|
+
CollapsibleTrigger,
|
|
17
|
+
} from '../../../components/ui/collapsible';
|
|
18
|
+
import {
|
|
19
|
+
Type,
|
|
20
|
+
ChevronRight,
|
|
21
|
+
AlignLeft,
|
|
22
|
+
AlignCenter,
|
|
23
|
+
AlignRight,
|
|
24
|
+
Bold,
|
|
25
|
+
Italic,
|
|
26
|
+
Underline,
|
|
27
|
+
} from 'lucide-react';
|
|
28
|
+
import { FONT_WEIGHTS } from '../../constants';
|
|
29
|
+
import { rgbToHex } from '../../utils/style-utils';
|
|
30
|
+
import { GoogleFontPicker } from './GoogleFontPicker';
|
|
31
|
+
import type { SelectedElementInfo } from '../../types';
|
|
32
|
+
|
|
33
|
+
interface TypographySectionProps {
|
|
34
|
+
selectedElement: SelectedElementInfo;
|
|
35
|
+
open: boolean;
|
|
36
|
+
onOpenChange: (open: boolean) => void;
|
|
37
|
+
onStyleChange: (styles: Record<string, string>) => void;
|
|
38
|
+
iframeDoc?: Document | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function TypographySection({
|
|
42
|
+
selectedElement,
|
|
43
|
+
open,
|
|
44
|
+
onOpenChange,
|
|
45
|
+
onStyleChange,
|
|
46
|
+
iframeDoc,
|
|
47
|
+
}: TypographySectionProps) {
|
|
48
|
+
return (
|
|
49
|
+
<Collapsible open={open} onOpenChange={onOpenChange}>
|
|
50
|
+
<CollapsibleTrigger className="flex items-center justify-between w-full py-2 text-xs font-medium text-gray-300 hover:text-white border-t border-[#444444]">
|
|
51
|
+
<span className="flex items-center gap-2">
|
|
52
|
+
<Type className="w-3.5 h-3.5" />
|
|
53
|
+
テキスト
|
|
54
|
+
</span>
|
|
55
|
+
<ChevronRight
|
|
56
|
+
className={`w-3.5 h-3.5 transition-transform ${open ? 'rotate-90' : ''}`}
|
|
57
|
+
/>
|
|
58
|
+
</CollapsibleTrigger>
|
|
59
|
+
<CollapsibleContent className="space-y-2 pb-3">
|
|
60
|
+
<div>
|
|
61
|
+
<Label className="text-[10px] text-gray-500">フォント</Label>
|
|
62
|
+
<GoogleFontPicker
|
|
63
|
+
value={selectedElement.fontFamily}
|
|
64
|
+
onChange={(value) => onStyleChange({ fontFamily: value })}
|
|
65
|
+
iframeDoc={iframeDoc}
|
|
66
|
+
className="w-full"
|
|
67
|
+
/>
|
|
68
|
+
</div>
|
|
69
|
+
<div className="grid grid-cols-2 gap-2">
|
|
70
|
+
<div>
|
|
71
|
+
<Label className="text-[10px] text-gray-500">ウェイト</Label>
|
|
72
|
+
<Select
|
|
73
|
+
value={selectedElement.fontWeight}
|
|
74
|
+
onValueChange={(value) => onStyleChange({ fontWeight: value })}
|
|
75
|
+
>
|
|
76
|
+
<SelectTrigger className="h-7 text-xs bg-[#383838] border-[#444444] text-white">
|
|
77
|
+
<SelectValue />
|
|
78
|
+
</SelectTrigger>
|
|
79
|
+
<SelectContent>
|
|
80
|
+
{FONT_WEIGHTS.map((w) => (
|
|
81
|
+
<SelectItem key={w.value} value={w.value}>
|
|
82
|
+
{w.label}
|
|
83
|
+
</SelectItem>
|
|
84
|
+
))}
|
|
85
|
+
</SelectContent>
|
|
86
|
+
</Select>
|
|
87
|
+
</div>
|
|
88
|
+
<div>
|
|
89
|
+
<Label className="text-[10px] text-gray-500">サイズ</Label>
|
|
90
|
+
<Input
|
|
91
|
+
type="number"
|
|
92
|
+
value={Math.round(selectedElement.fontSize)}
|
|
93
|
+
onChange={(e) => onStyleChange({ fontSize: `${e.target.value}px` })}
|
|
94
|
+
className="h-7 text-xs bg-[#383838] border-[#444444] text-white"
|
|
95
|
+
/>
|
|
96
|
+
</div>
|
|
97
|
+
</div>
|
|
98
|
+
<div className="grid grid-cols-2 gap-2">
|
|
99
|
+
<div>
|
|
100
|
+
<Label className="text-[10px] text-gray-500">行高</Label>
|
|
101
|
+
<Input
|
|
102
|
+
type="text"
|
|
103
|
+
value={selectedElement.lineHeight}
|
|
104
|
+
onChange={(e) => onStyleChange({ lineHeight: e.target.value })}
|
|
105
|
+
className="h-7 text-xs bg-[#383838] border-[#444444] text-white"
|
|
106
|
+
/>
|
|
107
|
+
</div>
|
|
108
|
+
<div>
|
|
109
|
+
<Label className="text-[10px] text-gray-500">字間</Label>
|
|
110
|
+
<Input
|
|
111
|
+
type="text"
|
|
112
|
+
value={selectedElement.letterSpacing}
|
|
113
|
+
onChange={(e) => onStyleChange({ letterSpacing: e.target.value })}
|
|
114
|
+
className="h-7 text-xs bg-[#383838] border-[#444444] text-white"
|
|
115
|
+
/>
|
|
116
|
+
</div>
|
|
117
|
+
</div>
|
|
118
|
+
<div>
|
|
119
|
+
<Label className="text-[10px] text-gray-500">配置</Label>
|
|
120
|
+
<div className="flex gap-1 mt-1">
|
|
121
|
+
<Button
|
|
122
|
+
variant="ghost"
|
|
123
|
+
size="icon"
|
|
124
|
+
onClick={() => onStyleChange({ textAlign: 'left' })}
|
|
125
|
+
className={`h-7 w-7 ${
|
|
126
|
+
selectedElement.textAlign === 'left'
|
|
127
|
+
? 'bg-[#0d99ff] text-white'
|
|
128
|
+
: 'text-gray-400 hover:text-white hover:bg-[#4a4a4a]'
|
|
129
|
+
}`}
|
|
130
|
+
>
|
|
131
|
+
<AlignLeft className="w-3.5 h-3.5" />
|
|
132
|
+
</Button>
|
|
133
|
+
<Button
|
|
134
|
+
variant="ghost"
|
|
135
|
+
size="icon"
|
|
136
|
+
onClick={() => onStyleChange({ textAlign: 'center' })}
|
|
137
|
+
className={`h-7 w-7 ${
|
|
138
|
+
selectedElement.textAlign === 'center'
|
|
139
|
+
? 'bg-[#0d99ff] text-white'
|
|
140
|
+
: 'text-gray-400 hover:text-white hover:bg-[#4a4a4a]'
|
|
141
|
+
}`}
|
|
142
|
+
>
|
|
143
|
+
<AlignCenter className="w-3.5 h-3.5" />
|
|
144
|
+
</Button>
|
|
145
|
+
<Button
|
|
146
|
+
variant="ghost"
|
|
147
|
+
size="icon"
|
|
148
|
+
onClick={() => onStyleChange({ textAlign: 'right' })}
|
|
149
|
+
className={`h-7 w-7 ${
|
|
150
|
+
selectedElement.textAlign === 'right'
|
|
151
|
+
? 'bg-[#0d99ff] text-white'
|
|
152
|
+
: 'text-gray-400 hover:text-white hover:bg-[#4a4a4a]'
|
|
153
|
+
}`}
|
|
154
|
+
>
|
|
155
|
+
<AlignRight className="w-3.5 h-3.5" />
|
|
156
|
+
</Button>
|
|
157
|
+
<div className="w-px h-7 bg-[#444444] mx-1" />
|
|
158
|
+
<Button
|
|
159
|
+
variant="ghost"
|
|
160
|
+
size="icon"
|
|
161
|
+
onClick={() =>
|
|
162
|
+
onStyleChange({
|
|
163
|
+
fontWeight: selectedElement.fontWeight === '700' ? '400' : '700',
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
className={`h-7 w-7 ${
|
|
167
|
+
selectedElement.fontWeight === '700'
|
|
168
|
+
? 'bg-[#0d99ff] text-white'
|
|
169
|
+
: 'text-gray-400 hover:text-white hover:bg-[#4a4a4a]'
|
|
170
|
+
}`}
|
|
171
|
+
>
|
|
172
|
+
<Bold className="w-3.5 h-3.5" />
|
|
173
|
+
</Button>
|
|
174
|
+
<Button
|
|
175
|
+
variant="ghost"
|
|
176
|
+
size="icon"
|
|
177
|
+
onClick={() =>
|
|
178
|
+
onStyleChange({
|
|
179
|
+
fontStyle: selectedElement.fontStyle === 'italic' ? 'normal' : 'italic',
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
className={`h-7 w-7 ${
|
|
183
|
+
selectedElement.fontStyle === 'italic'
|
|
184
|
+
? 'bg-[#0d99ff] text-white'
|
|
185
|
+
: 'text-gray-400 hover:text-white hover:bg-[#4a4a4a]'
|
|
186
|
+
}`}
|
|
187
|
+
>
|
|
188
|
+
<Italic className="w-3.5 h-3.5" />
|
|
189
|
+
</Button>
|
|
190
|
+
<Button
|
|
191
|
+
variant="ghost"
|
|
192
|
+
size="icon"
|
|
193
|
+
onClick={() =>
|
|
194
|
+
onStyleChange({
|
|
195
|
+
textDecoration: selectedElement.textDecoration.includes('underline')
|
|
196
|
+
? 'none'
|
|
197
|
+
: 'underline',
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
className={`h-7 w-7 ${
|
|
201
|
+
selectedElement.textDecoration.includes('underline')
|
|
202
|
+
? 'bg-[#0d99ff] text-white'
|
|
203
|
+
: 'text-gray-400 hover:text-white hover:bg-[#4a4a4a]'
|
|
204
|
+
}`}
|
|
205
|
+
>
|
|
206
|
+
<Underline className="w-3.5 h-3.5" />
|
|
207
|
+
</Button>
|
|
208
|
+
</div>
|
|
209
|
+
</div>
|
|
210
|
+
<div>
|
|
211
|
+
<Label className="text-[10px] text-gray-500">文字色</Label>
|
|
212
|
+
<div className="flex items-center gap-2 mt-1">
|
|
213
|
+
<input
|
|
214
|
+
type="color"
|
|
215
|
+
value={rgbToHex(selectedElement.color)}
|
|
216
|
+
onChange={(e) => onStyleChange({ color: e.target.value })}
|
|
217
|
+
className="w-8 h-7 rounded border border-[#444444] bg-transparent cursor-pointer"
|
|
218
|
+
/>
|
|
219
|
+
<Input
|
|
220
|
+
type="text"
|
|
221
|
+
value={rgbToHex(selectedElement.color)}
|
|
222
|
+
onChange={(e) => onStyleChange({ color: e.target.value })}
|
|
223
|
+
className="flex-1 h-7 text-xs bg-[#383838] border-[#444444] text-white font-mono"
|
|
224
|
+
/>
|
|
225
|
+
</div>
|
|
226
|
+
</div>
|
|
227
|
+
</CollapsibleContent>
|
|
228
|
+
</Collapsible>
|
|
229
|
+
);
|
|
230
|
+
}
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, { useCallback, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { parseValueWithUnit, formatValueWithUnit, SPACING_UNITS } from "./unit-utils";
|
|
5
|
+
|
|
6
|
+
export interface UnitAwareNumberInputProps {
|
|
7
|
+
/** CSS値文字列 (例: "16px", "1.5em", "100%") */
|
|
8
|
+
value: string | number | undefined;
|
|
9
|
+
/** 値変更時のコールバック */
|
|
10
|
+
onChange: (value: string) => void;
|
|
11
|
+
/** 使用可能な単位リスト */
|
|
12
|
+
units?: readonly string[];
|
|
13
|
+
/** デフォルト単位 */
|
|
14
|
+
defaultUnit?: string;
|
|
15
|
+
/** 最小値 */
|
|
16
|
+
min?: number;
|
|
17
|
+
/** 最大値 */
|
|
18
|
+
max?: number;
|
|
19
|
+
/** ステップ値 */
|
|
20
|
+
step?: number;
|
|
21
|
+
/** ラベル */
|
|
22
|
+
label?: string;
|
|
23
|
+
/** コンパクトモード */
|
|
24
|
+
compact?: boolean;
|
|
25
|
+
/** 無効化 */
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
/** 追加のクラス名 */
|
|
28
|
+
className?: string;
|
|
29
|
+
/** スクラブ機能を有効化 */
|
|
30
|
+
enableScrubbing?: boolean;
|
|
31
|
+
/** プレースホルダー */
|
|
32
|
+
placeholder?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 単位選択付き数値入力コンポーネント
|
|
37
|
+
* 既存のCompactNumberInputを置き換えずに、単位機能を追加した新しいコンポーネント
|
|
38
|
+
*/
|
|
39
|
+
export function UnitAwareNumberInput({
|
|
40
|
+
value,
|
|
41
|
+
onChange,
|
|
42
|
+
units = SPACING_UNITS,
|
|
43
|
+
defaultUnit = "px",
|
|
44
|
+
min,
|
|
45
|
+
max,
|
|
46
|
+
step = 1,
|
|
47
|
+
label,
|
|
48
|
+
compact = false,
|
|
49
|
+
disabled = false,
|
|
50
|
+
className,
|
|
51
|
+
enableScrubbing = true,
|
|
52
|
+
placeholder,
|
|
53
|
+
}: UnitAwareNumberInputProps) {
|
|
54
|
+
const inputRef = useRef<HTMLInputElement>(null);
|
|
55
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
56
|
+
const dragStartRef = useRef<{ x: number; startValue: number } | null>(null);
|
|
57
|
+
|
|
58
|
+
// 値をパース
|
|
59
|
+
const parsed = useMemo(
|
|
60
|
+
() => parseValueWithUnit(value, defaultUnit),
|
|
61
|
+
[value, defaultUnit]
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
// 特殊値(var(...), auto等)の場合は元の値を表示
|
|
65
|
+
const displayValue = parsed.isSpecial ? parsed.originalValue : parsed.numericValue;
|
|
66
|
+
const currentUnit = parsed.isSpecial ? defaultUnit : parsed.unit;
|
|
67
|
+
|
|
68
|
+
// 数値変更ハンドラ
|
|
69
|
+
const handleNumberChange = useCallback(
|
|
70
|
+
(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
71
|
+
const inputValue = e.target.value;
|
|
72
|
+
|
|
73
|
+
// 空の場合
|
|
74
|
+
if (inputValue === "" || inputValue === "-") {
|
|
75
|
+
onChange(formatValueWithUnit(0, currentUnit));
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const newNum = parseFloat(inputValue);
|
|
80
|
+
if (isNaN(newNum)) return;
|
|
81
|
+
|
|
82
|
+
// 範囲チェック
|
|
83
|
+
let clampedValue = newNum;
|
|
84
|
+
if (min !== undefined && newNum < min) clampedValue = min;
|
|
85
|
+
if (max !== undefined && newNum > max) clampedValue = max;
|
|
86
|
+
|
|
87
|
+
onChange(formatValueWithUnit(clampedValue, currentUnit));
|
|
88
|
+
},
|
|
89
|
+
[onChange, currentUnit, min, max]
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
// 単位変更ハンドラ
|
|
93
|
+
const handleUnitChange = useCallback(
|
|
94
|
+
(e: React.ChangeEvent<HTMLSelectElement>) => {
|
|
95
|
+
const newUnit = e.target.value;
|
|
96
|
+
|
|
97
|
+
// autoの場合は特別処理
|
|
98
|
+
if (newUnit === "auto") {
|
|
99
|
+
onChange("auto");
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 特殊値の場合は単位変更のみ(数値は0)
|
|
104
|
+
if (parsed.isSpecial) {
|
|
105
|
+
onChange(formatValueWithUnit(0, newUnit));
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
onChange(formatValueWithUnit(parsed.numericValue, newUnit));
|
|
110
|
+
},
|
|
111
|
+
[onChange, parsed]
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
// スクラブ開始
|
|
115
|
+
const handleMouseDown = useCallback(
|
|
116
|
+
(e: React.MouseEvent<HTMLInputElement>) => {
|
|
117
|
+
if (!enableScrubbing || disabled || parsed.isSpecial) return;
|
|
118
|
+
|
|
119
|
+
// 左クリックのみ
|
|
120
|
+
if (e.button !== 0) return;
|
|
121
|
+
|
|
122
|
+
// inputがフォーカスされている場合はスクラブしない
|
|
123
|
+
if (document.activeElement === inputRef.current) return;
|
|
124
|
+
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
setIsDragging(true);
|
|
127
|
+
dragStartRef.current = {
|
|
128
|
+
x: e.clientX,
|
|
129
|
+
startValue: parsed.numericValue,
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// マウスイベントリスナーを追加
|
|
133
|
+
const handleMouseMove = (moveEvent: MouseEvent) => {
|
|
134
|
+
if (!dragStartRef.current) return;
|
|
135
|
+
|
|
136
|
+
const delta = moveEvent.clientX - dragStartRef.current.x;
|
|
137
|
+
const sensitivity = moveEvent.shiftKey ? 0.1 : 1; // Shift押下で細かく調整
|
|
138
|
+
let newValue = dragStartRef.current.startValue + delta * sensitivity * step;
|
|
139
|
+
|
|
140
|
+
// 範囲チェック
|
|
141
|
+
if (min !== undefined && newValue < min) newValue = min;
|
|
142
|
+
if (max !== undefined && newValue > max) newValue = max;
|
|
143
|
+
|
|
144
|
+
// 小数点以下を適切に丸める
|
|
145
|
+
const precision = step < 1 ? Math.ceil(-Math.log10(step)) : 0;
|
|
146
|
+
newValue = Math.round(newValue * Math.pow(10, precision)) / Math.pow(10, precision);
|
|
147
|
+
|
|
148
|
+
onChange(formatValueWithUnit(newValue, currentUnit));
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const handleMouseUp = () => {
|
|
152
|
+
setIsDragging(false);
|
|
153
|
+
dragStartRef.current = null;
|
|
154
|
+
document.removeEventListener("mousemove", handleMouseMove);
|
|
155
|
+
document.removeEventListener("mouseup", handleMouseUp);
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
document.addEventListener("mousemove", handleMouseMove);
|
|
159
|
+
document.addEventListener("mouseup", handleMouseUp);
|
|
160
|
+
},
|
|
161
|
+
[enableScrubbing, disabled, parsed, step, min, max, currentUnit, onChange]
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
// キーボード操作
|
|
165
|
+
const handleKeyDown = useCallback(
|
|
166
|
+
(e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
167
|
+
if (disabled || parsed.isSpecial) return;
|
|
168
|
+
|
|
169
|
+
const multiplier = e.shiftKey ? 10 : 1;
|
|
170
|
+
let newValue = parsed.numericValue;
|
|
171
|
+
|
|
172
|
+
if (e.key === "ArrowUp") {
|
|
173
|
+
e.preventDefault();
|
|
174
|
+
newValue += step * multiplier;
|
|
175
|
+
} else if (e.key === "ArrowDown") {
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
newValue -= step * multiplier;
|
|
178
|
+
} else {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// 範囲チェック
|
|
183
|
+
if (min !== undefined && newValue < min) newValue = min;
|
|
184
|
+
if (max !== undefined && newValue > max) newValue = max;
|
|
185
|
+
|
|
186
|
+
onChange(formatValueWithUnit(newValue, currentUnit));
|
|
187
|
+
},
|
|
188
|
+
[disabled, parsed, step, min, max, currentUnit, onChange]
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
const inputWidth = compact ? "w-12" : "w-16";
|
|
192
|
+
const selectWidth = "w-14";
|
|
193
|
+
|
|
194
|
+
return (
|
|
195
|
+
<div className={`flex items-center gap-0.5 ${className || ""}`}>
|
|
196
|
+
{label && (
|
|
197
|
+
<span className="text-[10px] text-gray-500 w-6 flex-shrink-0">{label}</span>
|
|
198
|
+
)}
|
|
199
|
+
<div className="flex items-center">
|
|
200
|
+
<input
|
|
201
|
+
ref={inputRef}
|
|
202
|
+
type={parsed.isSpecial ? "text" : "number"}
|
|
203
|
+
value={displayValue}
|
|
204
|
+
onChange={handleNumberChange}
|
|
205
|
+
onMouseDown={handleMouseDown}
|
|
206
|
+
onKeyDown={handleKeyDown}
|
|
207
|
+
min={min}
|
|
208
|
+
max={max}
|
|
209
|
+
step={step}
|
|
210
|
+
disabled={disabled}
|
|
211
|
+
placeholder={placeholder}
|
|
212
|
+
className={`${inputWidth} h-6 px-1.5 text-[11px] border border-r-0 rounded-l border-gray-200
|
|
213
|
+
bg-white focus:outline-none focus:ring-1 focus:ring-[#0d99ff] focus:border-[#0d99ff]
|
|
214
|
+
disabled:bg-gray-50 disabled:text-gray-400
|
|
215
|
+
${isDragging ? "cursor-ew-resize" : enableScrubbing && !parsed.isSpecial ? "cursor-ew-resize" : ""}
|
|
216
|
+
[appearance:textfield] [&::-webkit-outer-spin-button]:appearance-none [&::-webkit-inner-spin-button]:appearance-none`}
|
|
217
|
+
style={{ MozAppearance: "textfield" }}
|
|
218
|
+
/>
|
|
219
|
+
<select
|
|
220
|
+
value={parsed.isSpecial && parsed.originalValue === "auto" ? "auto" : currentUnit}
|
|
221
|
+
onChange={handleUnitChange}
|
|
222
|
+
disabled={disabled}
|
|
223
|
+
className={`${selectWidth} h-6 px-1 text-[10px] border rounded-r border-gray-200
|
|
224
|
+
bg-gray-50 text-gray-600 focus:outline-none focus:ring-1 focus:ring-[#0d99ff]
|
|
225
|
+
disabled:bg-gray-100 disabled:text-gray-400 cursor-pointer`}
|
|
226
|
+
>
|
|
227
|
+
{units.map((u) => (
|
|
228
|
+
<option key={u} value={u}>
|
|
229
|
+
{u}
|
|
230
|
+
</option>
|
|
231
|
+
))}
|
|
232
|
+
</select>
|
|
233
|
+
</div>
|
|
234
|
+
</div>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export default UnitAwareNumberInput;
|