@open-slide/core 2.0.0-beta.3 → 2.0.0-beta.5
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 -1
- package/dist/{build-Bzy-qlGc.js → build-Cu5_qRyE.js} +1 -1
- package/dist/cli/bin.js +3 -3
- package/dist/{config-nbSvY7z_.js → config-BQ6rD2iE.js} +226 -27
- package/dist/{config-DjWifhaA.d.ts → config-GMR1QUlM.d.ts} +1 -1
- package/dist/{dev-MXa5Tod4.js → dev-BK641O5e.js} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/locale/index.d.ts +1 -1
- package/dist/locale/index.js +1 -1
- package/dist/{preview-DEpQcKz3.js → preview-BuCI-RMW.js} +1 -1
- package/dist/{types-BWg-Dtbg.d.ts → types-BcbaKTNY.d.ts} +60 -0
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +1 -1
- package/dist/{zh-tw-DlKyeNX7.js → zh-tw-B51sMTg3.js} +267 -31
- package/package.json +4 -4
- package/src/app/components/asset-view.tsx +448 -0
- package/src/app/components/history-provider.tsx +68 -44
- package/src/app/components/icon-switcher-indicator.tsx +10 -0
- package/src/app/components/inspector/arrange-panel.tsx +449 -0
- package/src/app/components/inspector/inline-text-editor.tsx +170 -284
- package/src/app/components/inspector/inspect-overlay.tsx +642 -295
- package/src/app/components/inspector/inspector-panel.tsx +434 -427
- package/src/app/components/inspector/inspector-provider.tsx +564 -293
- package/src/app/components/inspector/save-bar.tsx +36 -0
- package/src/app/components/panel/editor-sidebar.tsx +50 -0
- package/src/app/components/panel/panel-fields.tsx +204 -16
- package/src/app/components/panel/panel-shell.tsx +3 -18
- package/src/app/components/style-panel/style-panel.tsx +4 -69
- package/src/app/lib/assets.ts +33 -0
- package/src/app/lib/inspector/geometry.test.ts +324 -0
- package/src/app/lib/inspector/geometry.ts +207 -0
- package/src/app/lib/inspector/text-edit-timeline.test.ts +121 -0
- package/src/app/lib/inspector/text-edit-timeline.ts +12 -0
- package/src/app/lib/inspector/text-selection.ts +117 -0
- package/src/app/lib/inspector/use-editor.ts +1 -1
- package/src/app/lib/inspector/use-visual-editor.ts +429 -0
- package/src/app/lib/inspector/visual-dom.ts +255 -0
- package/src/app/lib/keys.ts +9 -0
- package/src/app/routes/slide.tsx +34 -9
- package/src/locale/en.ts +70 -8
- package/src/locale/ja.ts +72 -7
- package/src/locale/types.ts +60 -0
- package/src/locale/zh-cn.ts +68 -8
- package/src/locale/zh-tw.ts +68 -8
|
@@ -1,40 +1,54 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ALargeSmall,
|
|
2
3
|
AlignCenter,
|
|
3
4
|
AlignJustify,
|
|
4
5
|
AlignLeft,
|
|
5
6
|
AlignRight,
|
|
6
7
|
Bold,
|
|
7
8
|
Crop,
|
|
8
|
-
Crosshair,
|
|
9
9
|
ImageIcon,
|
|
10
10
|
Italic,
|
|
11
|
+
MousePointer2,
|
|
12
|
+
Move,
|
|
13
|
+
MoveHorizontal,
|
|
14
|
+
Paintbrush,
|
|
15
|
+
PencilLine,
|
|
16
|
+
Shapes,
|
|
17
|
+
Type,
|
|
18
|
+
UnfoldVertical,
|
|
11
19
|
X,
|
|
12
20
|
} from 'lucide-react';
|
|
13
|
-
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
21
|
+
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
22
|
+
import { IconSwitcherIndicator } from '@/components/icon-switcher-indicator';
|
|
23
|
+
import {
|
|
24
|
+
CollapsibleSection,
|
|
25
|
+
ColorField,
|
|
26
|
+
NumberField,
|
|
27
|
+
Section,
|
|
28
|
+
} from '@/components/panel/panel-fields';
|
|
29
|
+
import { PanelShell } from '@/components/panel/panel-shell';
|
|
16
30
|
import { Button } from '@/components/ui/button';
|
|
17
|
-
import { Input } from '@/components/ui/input';
|
|
18
31
|
import {
|
|
19
32
|
Select,
|
|
20
33
|
SelectContent,
|
|
34
|
+
SelectGroup,
|
|
21
35
|
SelectItem,
|
|
22
36
|
SelectTrigger,
|
|
23
37
|
SelectValue,
|
|
24
38
|
} from '@/components/ui/select';
|
|
25
|
-
import {
|
|
26
|
-
import { Slider } from '@/components/ui/slider';
|
|
39
|
+
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
|
27
40
|
import { Textarea } from '@/components/ui/textarea';
|
|
28
|
-
import { Toggle } from '@/components/ui/toggle';
|
|
29
41
|
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group';
|
|
30
42
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
|
|
31
43
|
import { findSlideSource } from '@/lib/inspector/fiber';
|
|
32
44
|
import { hasOnlyInlineTextChildren } from '@/lib/inspector/inline-text';
|
|
45
|
+
import { styleContext } from '@/lib/inspector/text-selection';
|
|
33
46
|
import type { EditOp } from '@/lib/inspector/use-editor';
|
|
34
47
|
import { useAgentSocketConnected } from '@/lib/use-agent-socket';
|
|
35
|
-
import { useLocale } from '@/lib/use-locale';
|
|
48
|
+
import { format, useLocale } from '@/lib/use-locale';
|
|
36
49
|
import { cn, round2 } from '@/lib/utils';
|
|
37
50
|
import type { Locale } from '../../../locale/types';
|
|
51
|
+
import { ArrangePanel } from './arrange-panel';
|
|
38
52
|
import { AssetPickerDialog } from './asset-picker-dialog';
|
|
39
53
|
import { type SelectedTarget, useInspector } from './inspector-provider';
|
|
40
54
|
|
|
@@ -72,11 +86,23 @@ function resolveSelectedTarget(target: SelectedTarget, slideId: string): Selecte
|
|
|
72
86
|
return { line: hit.line, column: hit.column, anchor: hit.anchor };
|
|
73
87
|
}
|
|
74
88
|
|
|
75
|
-
export function InspectorPanel(
|
|
89
|
+
export function InspectorPanel({
|
|
90
|
+
preferredTab,
|
|
91
|
+
onTabChange,
|
|
92
|
+
}: {
|
|
93
|
+
preferredTab: 'format' | 'arrange';
|
|
94
|
+
onTabChange: (tab: 'format' | 'arrange') => void;
|
|
95
|
+
}) {
|
|
76
96
|
const {
|
|
77
|
-
|
|
97
|
+
togglePanel,
|
|
98
|
+
inlineEdit,
|
|
99
|
+
inlineSelection,
|
|
100
|
+
startInlineEdit,
|
|
101
|
+
stopInlineEdit,
|
|
102
|
+
applyInlineStyle,
|
|
78
103
|
slideId,
|
|
79
104
|
selected,
|
|
105
|
+
selection,
|
|
80
106
|
setSelected,
|
|
81
107
|
bufferOps,
|
|
82
108
|
pendingCount,
|
|
@@ -96,7 +122,7 @@ export function InspectorPanel() {
|
|
|
96
122
|
setRangeStylePreview(null);
|
|
97
123
|
}, [selected]);
|
|
98
124
|
|
|
99
|
-
|
|
125
|
+
useLayoutEffect(() => {
|
|
100
126
|
void reloadCounter;
|
|
101
127
|
void pendingCount;
|
|
102
128
|
void opsVersion;
|
|
@@ -104,42 +130,10 @@ export function InspectorPanel() {
|
|
|
104
130
|
setSnapshot(null);
|
|
105
131
|
return;
|
|
106
132
|
}
|
|
107
|
-
|
|
108
|
-
if (!anchor.isConnected)
|
|
109
|
-
const next = findElementByLine(slideId, selected.line, selected.column);
|
|
110
|
-
if (next) {
|
|
111
|
-
anchor = next;
|
|
112
|
-
setSelected({ ...selected, anchor: next });
|
|
113
|
-
} else {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
133
|
+
const anchor = selected.anchor;
|
|
134
|
+
if (!anchor.isConnected) return;
|
|
117
135
|
setSnapshot(readSnapshot(anchor));
|
|
118
|
-
}, [selected,
|
|
119
|
-
|
|
120
|
-
// Freeze slide animations while editing so commits don't replay motion.
|
|
121
|
-
useEffect(() => {
|
|
122
|
-
if (!active) return;
|
|
123
|
-
const root = document.querySelector<HTMLElement>('[data-inspector-root]');
|
|
124
|
-
if (!root) return;
|
|
125
|
-
const styleEl = document.createElement('style');
|
|
126
|
-
styleEl.textContent = EDITING_FREEZE_CSS;
|
|
127
|
-
document.head.appendChild(styleEl);
|
|
128
|
-
root.dataset.inspectorEditing = 'true';
|
|
129
|
-
return () => {
|
|
130
|
-
let cleaned = false;
|
|
131
|
-
const finish = () => {
|
|
132
|
-
if (cleaned) return;
|
|
133
|
-
cleaned = true;
|
|
134
|
-
styleEl.remove();
|
|
135
|
-
delete root.dataset.inspectorEditing;
|
|
136
|
-
import.meta.hot?.off('vite:afterUpdate', finish);
|
|
137
|
-
clearTimeout(timer);
|
|
138
|
-
};
|
|
139
|
-
const timer = setTimeout(finish, 1500);
|
|
140
|
-
import.meta.hot?.on('vite:afterUpdate', finish);
|
|
141
|
-
};
|
|
142
|
-
}, [active]);
|
|
136
|
+
}, [selected, reloadCounter, pendingCount, opsVersion]);
|
|
143
137
|
|
|
144
138
|
const apply = useCallback(
|
|
145
139
|
(ops: EditOp[]) => {
|
|
@@ -152,45 +146,60 @@ export function InspectorPanel() {
|
|
|
152
146
|
[selected, setSelected, slideId, bufferOps],
|
|
153
147
|
);
|
|
154
148
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
const
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const
|
|
149
|
+
const multiple = selection.length > 1;
|
|
150
|
+
const tab = multiple ? 'arrange' : inlineEdit ? 'format' : preferredTab;
|
|
151
|
+
const textSelected = selected && snapshot?.text !== null && snapshot?.text !== undefined;
|
|
152
|
+
const imageSelected = Boolean(snapshot?.imageSrc || snapshot?.placeholder);
|
|
153
|
+
const elementLabel = multiple
|
|
154
|
+
? format(t.inspector.selectionCount, { count: selection.length })
|
|
155
|
+
: textSelected
|
|
156
|
+
? t.inspector.elementText
|
|
157
|
+
: imageSelected
|
|
158
|
+
? t.inspector.elementImage
|
|
159
|
+
: t.inspector.elementShape;
|
|
160
|
+
const ElementIcon = textSelected ? Type : imageSelected ? ImageIcon : Shapes;
|
|
161
|
+
const FormatIcon = textSelected ? Type : imageSelected ? ImageIcon : Paintbrush;
|
|
162
|
+
const formatLabel = textSelected
|
|
163
|
+
? t.inspector.elementText
|
|
164
|
+
: imageSelected
|
|
165
|
+
? t.inspector.elementImage
|
|
166
|
+
: t.inspector.styleLabel;
|
|
167
|
+
const selectedInlineRange =
|
|
168
|
+
inlineEdit?.anchor === selected?.anchor && inlineSelection ? inlineSelection : null;
|
|
174
169
|
const contentRange =
|
|
175
|
-
|
|
170
|
+
!inlineEdit &&
|
|
171
|
+
snapshot &&
|
|
172
|
+
snapshot.text !== null &&
|
|
173
|
+
contentSelection &&
|
|
174
|
+
contentSelection.end > contentSelection.start
|
|
176
175
|
? contentSelection
|
|
177
176
|
: null;
|
|
178
177
|
const rangePreviewApplies =
|
|
179
178
|
contentRange &&
|
|
180
179
|
rangeStylePreview &&
|
|
181
|
-
rangeStylePreview.anchor ===
|
|
180
|
+
rangeStylePreview.anchor === selected?.anchor &&
|
|
182
181
|
rangeStylePreview.start === contentRange.start &&
|
|
183
182
|
rangeStylePreview.end === contentRange.end;
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
183
|
+
const rangeSnapshot =
|
|
184
|
+
selected && selectedInlineRange && snapshot
|
|
185
|
+
? { ...snapshot, ...readTypography(styleContext(selected.anchor, selectedInlineRange)) }
|
|
186
|
+
: snapshot;
|
|
187
|
+
const typographySnapshot =
|
|
188
|
+
rangePreviewApplies && rangeSnapshot
|
|
189
|
+
? { ...rangeSnapshot, ...rangeStylePreview.values }
|
|
190
|
+
: rangeSnapshot;
|
|
187
191
|
const applyTextStyle = (ops: EditOp[]) => {
|
|
192
|
+
if (!selected || !snapshot) return;
|
|
193
|
+
if (applyInlineStyle(ops)) {
|
|
194
|
+
if (selected.anchor.isConnected) setSnapshot(readSnapshot(selected.anchor));
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
188
197
|
const styleOps = ops.flatMap((op) => (op.kind === 'set-style' ? [op] : []));
|
|
189
|
-
const target = resolveSelectedTarget(
|
|
190
|
-
if (target !==
|
|
198
|
+
const target = resolveSelectedTarget(selected, slideId);
|
|
199
|
+
if (target !== selected) setSelected(target);
|
|
191
200
|
if (
|
|
192
201
|
contentRange &&
|
|
193
|
-
|
|
202
|
+
snapshot.text !== null &&
|
|
194
203
|
styleOps.length === 1 &&
|
|
195
204
|
styleOps.length === ops.length &&
|
|
196
205
|
styleOps.every((op) => INLINE_CONTENT_STYLE_KEYS.has(op.key))
|
|
@@ -205,7 +214,7 @@ export function InspectorPanel() {
|
|
|
205
214
|
end: contentRange.end,
|
|
206
215
|
key: op.key,
|
|
207
216
|
value: op.value,
|
|
208
|
-
prevText:
|
|
217
|
+
prevText: snapshot.text ?? undefined,
|
|
209
218
|
})),
|
|
210
219
|
);
|
|
211
220
|
setRangeStylePreview((current) => ({
|
|
@@ -225,7 +234,7 @@ export function InspectorPanel() {
|
|
|
225
234
|
return;
|
|
226
235
|
}
|
|
227
236
|
if (
|
|
228
|
-
|
|
237
|
+
snapshot.text !== null &&
|
|
229
238
|
styleOps.length > 0 &&
|
|
230
239
|
styleOps.length === ops.length &&
|
|
231
240
|
styleOps.every((op) => INLINE_CONTENT_STYLE_KEYS.has(op.key))
|
|
@@ -234,7 +243,7 @@ export function InspectorPanel() {
|
|
|
234
243
|
target.line,
|
|
235
244
|
target.column,
|
|
236
245
|
target.anchor,
|
|
237
|
-
styleOps.map((op) => ({ ...op, prevText:
|
|
246
|
+
styleOps.map((op) => ({ ...op, prevText: snapshot.text ?? undefined })),
|
|
238
247
|
);
|
|
239
248
|
if (target.anchor.isConnected) setSnapshot(readSnapshot(target.anchor));
|
|
240
249
|
return;
|
|
@@ -242,120 +251,203 @@ export function InspectorPanel() {
|
|
|
242
251
|
apply(ops);
|
|
243
252
|
};
|
|
244
253
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
<span
|
|
257
|
-
|
|
258
|
-
<{pinSelected.anchor.tagName.toLowerCase()}>
|
|
254
|
+
const rangeSelected = Boolean(
|
|
255
|
+
selectedInlineRange && selectedInlineRange.end > selectedInlineRange.start,
|
|
256
|
+
);
|
|
257
|
+
const footer =
|
|
258
|
+
selected && snapshot && !multiple ? (
|
|
259
|
+
<>
|
|
260
|
+
<CollapsibleSection title={t.inspector.leaveComment}>
|
|
261
|
+
<CommentsSection selected={selected} onAdd={add} />
|
|
262
|
+
</CollapsibleSection>
|
|
263
|
+
<CollapsibleSection title={t.inspector.sourceSection}>
|
|
264
|
+
<div className="flex items-center justify-between gap-2">
|
|
265
|
+
<span className="font-mono text-[10.5px] text-muted-foreground">
|
|
266
|
+
<{selected.anchor.tagName.toLowerCase()}> · {selected.line}:{selected.column}
|
|
259
267
|
</span>
|
|
260
|
-
</div>
|
|
261
|
-
<div className="flex items-center gap-1.5">
|
|
262
268
|
<AgentWatchingBadge />
|
|
269
|
+
</div>
|
|
270
|
+
</CollapsibleSection>
|
|
271
|
+
</>
|
|
272
|
+
) : undefined;
|
|
273
|
+
|
|
274
|
+
return (
|
|
275
|
+
<Tabs
|
|
276
|
+
value={tab}
|
|
277
|
+
onValueChange={(value) => {
|
|
278
|
+
if (value === 'arrange') stopInlineEdit();
|
|
279
|
+
if (value === 'format' || value === 'arrange') onTabChange(value);
|
|
280
|
+
}}
|
|
281
|
+
className="h-full shrink-0 gap-0"
|
|
282
|
+
onPointerDownCapture={(event) => {
|
|
283
|
+
if (!inlineEdit || !(event.target instanceof Element)) return;
|
|
284
|
+
const button = event.target.closest('button');
|
|
285
|
+
if (button && !button.matches('[aria-haspopup], [role="tab"]')) event.preventDefault();
|
|
286
|
+
}}
|
|
287
|
+
>
|
|
288
|
+
<PanelShell
|
|
289
|
+
uiAttr="inspector"
|
|
290
|
+
header={
|
|
291
|
+
<>
|
|
292
|
+
<div className="flex min-w-0 items-center gap-2">
|
|
293
|
+
<Paintbrush className="size-3.5 text-muted-foreground" />
|
|
294
|
+
<span className="font-heading text-[12px] font-semibold tracking-tight">
|
|
295
|
+
{t.inspector.format}
|
|
296
|
+
</span>
|
|
297
|
+
</div>
|
|
263
298
|
<Button
|
|
264
299
|
variant="ghost"
|
|
265
300
|
size="icon-sm"
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
aria-label={t.inspector.deselect}
|
|
301
|
+
onClick={togglePanel}
|
|
302
|
+
aria-label={t.inspector.closeFormatPanel}
|
|
269
303
|
>
|
|
270
|
-
<X
|
|
304
|
+
<X />
|
|
271
305
|
</Button>
|
|
306
|
+
</>
|
|
307
|
+
}
|
|
308
|
+
banner={
|
|
309
|
+
selected && snapshot ? (
|
|
310
|
+
<div className="flex shrink-0 items-center justify-between gap-3 px-3.5 pt-3.5 pb-1">
|
|
311
|
+
<div className="flex min-w-0 items-center gap-2 text-[12px] font-medium">
|
|
312
|
+
<ElementIcon aria-hidden className="size-4 shrink-0 text-muted-foreground" />
|
|
313
|
+
<span className="truncate">{elementLabel}</span>
|
|
314
|
+
</div>
|
|
315
|
+
<TabsList
|
|
316
|
+
className="relative isolate shrink-0 rounded-lg group-data-[orientation=horizontal]/tabs:h-8"
|
|
317
|
+
aria-label={t.inspector.format}
|
|
318
|
+
>
|
|
319
|
+
<IconSwitcherIndicator index={tab === 'arrange' ? 1 : 0} />
|
|
320
|
+
<TabsTrigger
|
|
321
|
+
value="format"
|
|
322
|
+
disabled={multiple}
|
|
323
|
+
title={formatLabel}
|
|
324
|
+
className="z-10 h-full w-8 flex-none rounded-md px-0 data-active:bg-transparent data-active:shadow-none dark:data-active:bg-transparent"
|
|
325
|
+
>
|
|
326
|
+
<FormatIcon aria-hidden />
|
|
327
|
+
<span className="sr-only">{formatLabel}</span>
|
|
328
|
+
</TabsTrigger>
|
|
329
|
+
<TabsTrigger
|
|
330
|
+
value="arrange"
|
|
331
|
+
title={t.inspector.arrangeSection}
|
|
332
|
+
className="z-10 h-full w-8 flex-none rounded-md px-0 data-active:bg-transparent data-active:shadow-none dark:data-active:bg-transparent"
|
|
333
|
+
>
|
|
334
|
+
<Move aria-hidden />
|
|
335
|
+
<span className="sr-only">{t.inspector.arrangeSection}</span>
|
|
336
|
+
</TabsTrigger>
|
|
337
|
+
</TabsList>
|
|
338
|
+
</div>
|
|
339
|
+
) : undefined
|
|
340
|
+
}
|
|
341
|
+
footer={footer}
|
|
342
|
+
>
|
|
343
|
+
{selected && snapshot && typographySnapshot ? (
|
|
344
|
+
<>
|
|
345
|
+
<TabsContent value="format">
|
|
346
|
+
{textSelected && (
|
|
347
|
+
<Section title={t.inspector.typographySection}>
|
|
348
|
+
{rangeSelected && (
|
|
349
|
+
<p className="text-[11px] leading-relaxed text-muted-foreground">
|
|
350
|
+
{t.inspector.textSelectionHint}
|
|
351
|
+
</p>
|
|
352
|
+
)}
|
|
353
|
+
<div className="flex items-center gap-1.5">
|
|
354
|
+
<FontWeightField snapshot={typographySnapshot} apply={applyTextStyle} />
|
|
355
|
+
<FontSizeField snapshot={typographySnapshot} apply={applyTextStyle} />
|
|
356
|
+
</div>
|
|
357
|
+
<div className="flex items-center gap-2">
|
|
358
|
+
<StyleToggles snapshot={typographySnapshot} apply={applyTextStyle} />
|
|
359
|
+
<TextAlignField snapshot={snapshot} apply={apply} />
|
|
360
|
+
</div>
|
|
361
|
+
<div className="flex items-center gap-1.5">
|
|
362
|
+
<LineHeightField snapshot={snapshot} apply={apply} />
|
|
363
|
+
<LetterSpacingField snapshot={snapshot} apply={apply} />
|
|
364
|
+
</div>
|
|
365
|
+
</Section>
|
|
366
|
+
)}
|
|
367
|
+
{snapshot.imageSrc !== null && (
|
|
368
|
+
<Section title={t.inspector.imageSection}>
|
|
369
|
+
<ImageField src={snapshot.imageSrc} anchor={selected.anchor} />
|
|
370
|
+
</Section>
|
|
371
|
+
)}
|
|
372
|
+
{snapshot.placeholder && (
|
|
373
|
+
<Section title={t.inspector.imagePlaceholderSection}>
|
|
374
|
+
<PlaceholderField
|
|
375
|
+
slideId={slideId}
|
|
376
|
+
hint={snapshot.placeholder.hint}
|
|
377
|
+
line={selected.line}
|
|
378
|
+
column={selected.column}
|
|
379
|
+
applyEdit={applyEdit}
|
|
380
|
+
/>
|
|
381
|
+
</Section>
|
|
382
|
+
)}
|
|
383
|
+
<Section title={t.inspector.colorSection}>
|
|
384
|
+
{textSelected && (
|
|
385
|
+
<ColorField
|
|
386
|
+
label={t.inspector.textColor}
|
|
387
|
+
value={typographySnapshot.color}
|
|
388
|
+
onChange={(value) =>
|
|
389
|
+
applyTextStyle([{ kind: 'set-style', key: 'color', value }])
|
|
390
|
+
}
|
|
391
|
+
/>
|
|
392
|
+
)}
|
|
393
|
+
<ColorField
|
|
394
|
+
label={t.inspector.backgroundColor}
|
|
395
|
+
value={snapshot.backgroundColor ?? '#ffffff'}
|
|
396
|
+
dim={!snapshot.backgroundColor}
|
|
397
|
+
onChange={(value) =>
|
|
398
|
+
apply([{ kind: 'set-style', key: 'backgroundColor', value }])
|
|
399
|
+
}
|
|
400
|
+
onClear={
|
|
401
|
+
snapshot.backgroundColor
|
|
402
|
+
? () => apply([{ kind: 'set-style', key: 'backgroundColor', value: null }])
|
|
403
|
+
: undefined
|
|
404
|
+
}
|
|
405
|
+
/>
|
|
406
|
+
</Section>
|
|
407
|
+
{textSelected && (
|
|
408
|
+
<Section
|
|
409
|
+
title={t.inspector.contentSection}
|
|
410
|
+
action={
|
|
411
|
+
<Button
|
|
412
|
+
variant="ghost"
|
|
413
|
+
size="xs"
|
|
414
|
+
className="text-muted-foreground hover:text-foreground"
|
|
415
|
+
onClick={() => startInlineEdit(selected)}
|
|
416
|
+
>
|
|
417
|
+
<PencilLine data-icon="inline-start" />
|
|
418
|
+
{t.inspector.editText}
|
|
419
|
+
</Button>
|
|
420
|
+
}
|
|
421
|
+
>
|
|
422
|
+
<ContentField
|
|
423
|
+
snapshot={snapshot}
|
|
424
|
+
apply={apply}
|
|
425
|
+
onFocus={stopInlineEdit}
|
|
426
|
+
onSelectionChange={setContentSelection}
|
|
427
|
+
/>
|
|
428
|
+
</Section>
|
|
429
|
+
)}
|
|
430
|
+
</TabsContent>
|
|
431
|
+
<TabsContent value="arrange">
|
|
432
|
+
<ArrangePanel />
|
|
433
|
+
</TabsContent>
|
|
434
|
+
</>
|
|
435
|
+
) : (
|
|
436
|
+
<div className="flex flex-col items-center gap-3 px-7 py-16 text-center">
|
|
437
|
+
<MousePointer2 aria-hidden className="size-8 text-muted-foreground/50" />
|
|
438
|
+
<div className="flex flex-col gap-1.5">
|
|
439
|
+
<h2 className="text-[13px] font-medium">{t.inspector.emptySelectionTitle}</h2>
|
|
440
|
+
<p className="text-[12px] leading-relaxed text-muted-foreground">
|
|
441
|
+
{t.inspector.emptySelectionHint}
|
|
442
|
+
</p>
|
|
443
|
+
</div>
|
|
272
444
|
</div>
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
>
|
|
277
|
-
{pinSnapshot.text !== null && (
|
|
278
|
-
<>
|
|
279
|
-
<Section title={t.inspector.contentSection}>
|
|
280
|
-
<ContentField
|
|
281
|
-
snapshot={pinSnapshot}
|
|
282
|
-
apply={apply}
|
|
283
|
-
onSelectionChange={setContentSelection}
|
|
284
|
-
/>
|
|
285
|
-
</Section>
|
|
286
|
-
<Separator />
|
|
287
|
-
</>
|
|
288
|
-
)}
|
|
289
|
-
|
|
290
|
-
<Section title={t.inspector.typographySection}>
|
|
291
|
-
<FontSizeField snapshot={typographySnapshot} apply={applyTextStyle} />
|
|
292
|
-
<FontWeightField snapshot={typographySnapshot} apply={applyTextStyle} />
|
|
293
|
-
<StyleToggles snapshot={typographySnapshot} apply={applyTextStyle} />
|
|
294
|
-
<LineHeightField snapshot={pinSnapshot} apply={apply} />
|
|
295
|
-
<LetterSpacingField snapshot={pinSnapshot} apply={apply} />
|
|
296
|
-
<TextAlignField snapshot={pinSnapshot} apply={apply} />
|
|
297
|
-
</Section>
|
|
298
|
-
|
|
299
|
-
<Separator />
|
|
300
|
-
|
|
301
|
-
<Section title={t.inspector.colorSection}>
|
|
302
|
-
<ColorField
|
|
303
|
-
label={t.inspector.textColor}
|
|
304
|
-
value={typographySnapshot.color}
|
|
305
|
-
onChange={(v) => applyTextStyle([{ kind: 'set-style', key: 'color', value: v }])}
|
|
306
|
-
clearable={false}
|
|
307
|
-
/>
|
|
308
|
-
<ColorField
|
|
309
|
-
label={t.inspector.backgroundColor}
|
|
310
|
-
value={pinSnapshot.backgroundColor ?? '#ffffff'}
|
|
311
|
-
dim={!pinSnapshot.backgroundColor}
|
|
312
|
-
onChange={(v) => apply([{ kind: 'set-style', key: 'backgroundColor', value: v }])}
|
|
313
|
-
onClear={() => apply([{ kind: 'set-style', key: 'backgroundColor', value: null }])}
|
|
314
|
-
clearable
|
|
315
|
-
/>
|
|
316
|
-
</Section>
|
|
317
|
-
|
|
318
|
-
{pinSnapshot.imageSrc !== null && (
|
|
319
|
-
<>
|
|
320
|
-
<Separator />
|
|
321
|
-
<Section title={t.inspector.imageSection}>
|
|
322
|
-
<ImageField src={pinSnapshot.imageSrc} anchor={pinSelected.anchor} />
|
|
323
|
-
</Section>
|
|
324
|
-
</>
|
|
325
|
-
)}
|
|
326
|
-
|
|
327
|
-
{pinSnapshot.placeholder && (
|
|
328
|
-
<>
|
|
329
|
-
<Separator />
|
|
330
|
-
<Section title={t.inspector.imagePlaceholderSection}>
|
|
331
|
-
<PlaceholderField
|
|
332
|
-
slideId={slideId}
|
|
333
|
-
hint={pinSnapshot.placeholder.hint}
|
|
334
|
-
line={pinSelected.line}
|
|
335
|
-
column={pinSelected.column}
|
|
336
|
-
applyEdit={applyEdit}
|
|
337
|
-
/>
|
|
338
|
-
</Section>
|
|
339
|
-
</>
|
|
340
|
-
)}
|
|
341
|
-
</PanelShell>
|
|
445
|
+
)}
|
|
446
|
+
</PanelShell>
|
|
447
|
+
</Tabs>
|
|
342
448
|
);
|
|
343
449
|
}
|
|
344
450
|
|
|
345
|
-
const EDITING_FREEZE_CSS = `
|
|
346
|
-
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *),
|
|
347
|
-
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *)::before,
|
|
348
|
-
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *)::after {
|
|
349
|
-
animation-duration: 1ms !important;
|
|
350
|
-
animation-delay: 0s !important;
|
|
351
|
-
animation-iteration-count: 1 !important;
|
|
352
|
-
animation-fill-mode: forwards !important;
|
|
353
|
-
transition: none !important;
|
|
354
|
-
view-transition-name: none !important;
|
|
355
|
-
cursor: pointer !important;
|
|
356
|
-
}
|
|
357
|
-
`;
|
|
358
|
-
|
|
359
451
|
const INLINE_CONTENT_STYLE_KEYS = new Set([
|
|
360
452
|
'fontSize',
|
|
361
453
|
'fontWeight',
|
|
@@ -384,10 +476,12 @@ function stylePreviewFromOps(ops: Array<Extract<EditOp, { kind: 'set-style' }>>)
|
|
|
384
476
|
function ContentField({
|
|
385
477
|
snapshot,
|
|
386
478
|
apply,
|
|
479
|
+
onFocus,
|
|
387
480
|
onSelectionChange,
|
|
388
481
|
}: {
|
|
389
482
|
snapshot: ElementSnapshot;
|
|
390
483
|
apply: (ops: EditOp[]) => void;
|
|
484
|
+
onFocus: () => void;
|
|
391
485
|
onSelectionChange?: (selection: ContentSelection | null) => void;
|
|
392
486
|
}) {
|
|
393
487
|
// Mirror the value locally and skip syncs during IME composition;
|
|
@@ -409,6 +503,8 @@ function ContentField({
|
|
|
409
503
|
|
|
410
504
|
return (
|
|
411
505
|
<Textarea
|
|
506
|
+
aria-label={t.inspector.elementTextPlaceholder}
|
|
507
|
+
onFocus={onFocus}
|
|
412
508
|
value={local}
|
|
413
509
|
onCompositionStart={() => {
|
|
414
510
|
composingRef.current = true;
|
|
@@ -446,28 +542,20 @@ function FontSizeField({
|
|
|
446
542
|
snapshot: ElementSnapshot;
|
|
447
543
|
apply: (ops: EditOp[]) => void;
|
|
448
544
|
}) {
|
|
449
|
-
const set = (px: number) => {
|
|
450
|
-
apply([{ kind: 'set-style', key: 'fontSize', value: `${Math.round(px)}px` }]);
|
|
451
|
-
};
|
|
452
545
|
const t = useLocale();
|
|
453
546
|
return (
|
|
454
|
-
<
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
value
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
min={1}
|
|
467
|
-
max={400}
|
|
468
|
-
suffix="px"
|
|
469
|
-
/>
|
|
470
|
-
</Field>
|
|
547
|
+
<NumberField
|
|
548
|
+
icon={ALargeSmall}
|
|
549
|
+
label={t.inspector.sizeLabel}
|
|
550
|
+
value={Math.round(snapshot.fontSize)}
|
|
551
|
+
onChange={(px) =>
|
|
552
|
+
apply([{ kind: 'set-style', key: 'fontSize', value: `${Math.round(px)}px` }])
|
|
553
|
+
}
|
|
554
|
+
min={1}
|
|
555
|
+
max={400}
|
|
556
|
+
suffix="px"
|
|
557
|
+
className="w-24"
|
|
558
|
+
/>
|
|
471
559
|
);
|
|
472
560
|
}
|
|
473
561
|
|
|
@@ -492,33 +580,33 @@ function FontWeightField({
|
|
|
492
580
|
const t = useLocale();
|
|
493
581
|
const weightOptions = getWeightOptions(t);
|
|
494
582
|
return (
|
|
495
|
-
<
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
},
|
|
507
|
-
]);
|
|
508
|
-
}}
|
|
583
|
+
<Select
|
|
584
|
+
items={Object.fromEntries(weightOptions.map((opt) => [opt.value, opt.label]))}
|
|
585
|
+
value={String(snapshot.fontWeight)}
|
|
586
|
+
onValueChange={(value) => {
|
|
587
|
+
apply([{ kind: 'set-style', key: 'fontWeight', value: String(Number(value)) }]);
|
|
588
|
+
}}
|
|
589
|
+
>
|
|
590
|
+
<SelectTrigger
|
|
591
|
+
size="sm"
|
|
592
|
+
className="min-w-0 flex-1 text-xs"
|
|
593
|
+
aria-label={t.inspector.weightLabel}
|
|
509
594
|
>
|
|
510
|
-
<
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
<
|
|
595
|
+
<SelectValue />
|
|
596
|
+
</SelectTrigger>
|
|
597
|
+
<SelectContent>
|
|
598
|
+
<SelectGroup>
|
|
514
599
|
{weightOptions.map((opt) => (
|
|
515
600
|
<SelectItem key={opt.value} value={opt.value} className="text-xs">
|
|
516
601
|
{opt.label}
|
|
602
|
+
<span aria-hidden className="ml-1.5 font-mono text-[10.5px] opacity-60">
|
|
603
|
+
{opt.value}
|
|
604
|
+
</span>
|
|
517
605
|
</SelectItem>
|
|
518
606
|
))}
|
|
519
|
-
</
|
|
520
|
-
</
|
|
521
|
-
</
|
|
607
|
+
</SelectGroup>
|
|
608
|
+
</SelectContent>
|
|
609
|
+
</Select>
|
|
522
610
|
);
|
|
523
611
|
}
|
|
524
612
|
|
|
@@ -530,31 +618,50 @@ function StyleToggles({
|
|
|
530
618
|
apply: (ops: EditOp[]) => void;
|
|
531
619
|
}) {
|
|
532
620
|
const t = useLocale();
|
|
621
|
+
const bold = snapshot.fontWeight >= 600;
|
|
622
|
+
const italic = snapshot.fontStyle === 'italic';
|
|
623
|
+
const value = [...(bold ? ['bold'] : []), ...(italic ? ['italic'] : [])];
|
|
533
624
|
return (
|
|
534
|
-
<
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
625
|
+
<ToggleGroup
|
|
626
|
+
multiple
|
|
627
|
+
size="sm"
|
|
628
|
+
variant="outline"
|
|
629
|
+
value={value}
|
|
630
|
+
onValueChange={(next) => {
|
|
631
|
+
const ops: EditOp[] = [];
|
|
632
|
+
const nextBold = next.includes('bold');
|
|
633
|
+
const nextItalic = next.includes('italic');
|
|
634
|
+
if (nextBold !== bold) {
|
|
635
|
+
ops.push({ kind: 'set-style', key: 'fontWeight', value: nextBold ? '700' : '400' });
|
|
636
|
+
}
|
|
637
|
+
if (nextItalic !== italic) {
|
|
638
|
+
ops.push({
|
|
639
|
+
kind: 'set-style',
|
|
640
|
+
key: 'fontStyle',
|
|
641
|
+
value: nextItalic ? 'italic' : 'normal',
|
|
642
|
+
});
|
|
541
643
|
}
|
|
644
|
+
if (ops.length > 0) apply(ops);
|
|
645
|
+
}}
|
|
646
|
+
aria-label={t.inspector.styleLabel}
|
|
647
|
+
>
|
|
648
|
+
<ToggleGroupItem
|
|
649
|
+
value="bold"
|
|
542
650
|
aria-label={t.inspector.boldAria}
|
|
651
|
+
title={t.inspector.boldAria}
|
|
652
|
+
className="size-7 px-0"
|
|
543
653
|
>
|
|
544
|
-
<Bold
|
|
545
|
-
</
|
|
546
|
-
<
|
|
547
|
-
|
|
548
|
-
variant="outline"
|
|
549
|
-
pressed={snapshot.fontStyle === 'italic'}
|
|
550
|
-
onPressedChange={(v) =>
|
|
551
|
-
apply([{ kind: 'set-style', key: 'fontStyle', value: v ? 'italic' : null }])
|
|
552
|
-
}
|
|
654
|
+
<Bold />
|
|
655
|
+
</ToggleGroupItem>
|
|
656
|
+
<ToggleGroupItem
|
|
657
|
+
value="italic"
|
|
553
658
|
aria-label={t.inspector.italicAria}
|
|
659
|
+
title={t.inspector.italicAria}
|
|
660
|
+
className="size-7 px-0"
|
|
554
661
|
>
|
|
555
|
-
<Italic
|
|
556
|
-
</
|
|
557
|
-
</
|
|
662
|
+
<Italic />
|
|
663
|
+
</ToggleGroupItem>
|
|
664
|
+
</ToggleGroup>
|
|
558
665
|
);
|
|
559
666
|
}
|
|
560
667
|
|
|
@@ -565,23 +672,18 @@ function LineHeightField({
|
|
|
565
672
|
snapshot: ElementSnapshot;
|
|
566
673
|
apply: (ops: EditOp[]) => void;
|
|
567
674
|
}) {
|
|
568
|
-
const v = snapshot.lineHeight ?? 1.4;
|
|
569
|
-
const set = (n: number) => {
|
|
570
|
-
apply([{ kind: 'set-style', key: 'lineHeight', value: String(round2(n)) }]);
|
|
571
|
-
};
|
|
572
675
|
const t = useLocale();
|
|
573
676
|
return (
|
|
574
|
-
<
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
</Field>
|
|
677
|
+
<NumberField
|
|
678
|
+
icon={UnfoldVertical}
|
|
679
|
+
label={t.inspector.lineHeightLabel}
|
|
680
|
+
value={round2(snapshot.lineHeight ?? 1.4)}
|
|
681
|
+
onChange={(n) => apply([{ kind: 'set-style', key: 'lineHeight', value: String(round2(n)) }])}
|
|
682
|
+
step={0.05}
|
|
683
|
+
min={0.5}
|
|
684
|
+
max={5}
|
|
685
|
+
className="basis-0 grow"
|
|
686
|
+
/>
|
|
585
687
|
);
|
|
586
688
|
}
|
|
587
689
|
|
|
@@ -592,37 +694,23 @@ function LetterSpacingField({
|
|
|
592
694
|
snapshot: ElementSnapshot;
|
|
593
695
|
apply: (ops: EditOp[]) => void;
|
|
594
696
|
}) {
|
|
595
|
-
const set = (n: number) => {
|
|
596
|
-
apply([
|
|
597
|
-
{
|
|
598
|
-
kind: 'set-style',
|
|
599
|
-
key: 'letterSpacing',
|
|
600
|
-
value: n === 0 ? null : `${round2(n)}px`,
|
|
601
|
-
},
|
|
602
|
-
]);
|
|
603
|
-
};
|
|
604
697
|
const t = useLocale();
|
|
605
698
|
return (
|
|
606
|
-
<
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
min={-20}
|
|
622
|
-
max={50}
|
|
623
|
-
suffix="px"
|
|
624
|
-
/>
|
|
625
|
-
</Field>
|
|
699
|
+
<NumberField
|
|
700
|
+
icon={MoveHorizontal}
|
|
701
|
+
label={t.inspector.trackingLabel}
|
|
702
|
+
value={round2(snapshot.letterSpacing)}
|
|
703
|
+
onChange={(n) =>
|
|
704
|
+
apply([
|
|
705
|
+
{ kind: 'set-style', key: 'letterSpacing', value: n === 0 ? null : `${round2(n)}px` },
|
|
706
|
+
])
|
|
707
|
+
}
|
|
708
|
+
step={0.1}
|
|
709
|
+
min={-20}
|
|
710
|
+
max={50}
|
|
711
|
+
suffix="px"
|
|
712
|
+
className="basis-0 grow"
|
|
713
|
+
/>
|
|
626
714
|
);
|
|
627
715
|
}
|
|
628
716
|
|
|
@@ -642,104 +730,23 @@ function TextAlignField({
|
|
|
642
730
|
}) {
|
|
643
731
|
const t = useLocale();
|
|
644
732
|
return (
|
|
645
|
-
<
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
{ALIGN_OPTIONS.map(({ v, icon: Icon }) => (
|
|
663
|
-
<ToggleGroupItem key={v} value={v} aria-label={v} className="size-8">
|
|
664
|
-
<Icon className="size-3.5" />
|
|
665
|
-
</ToggleGroupItem>
|
|
666
|
-
))}
|
|
667
|
-
</ToggleGroup>
|
|
668
|
-
</Field>
|
|
669
|
-
);
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
function ColorField({
|
|
673
|
-
label,
|
|
674
|
-
value,
|
|
675
|
-
dim,
|
|
676
|
-
onChange,
|
|
677
|
-
onClear,
|
|
678
|
-
clearable,
|
|
679
|
-
}: {
|
|
680
|
-
label: string;
|
|
681
|
-
value: string;
|
|
682
|
-
dim?: boolean;
|
|
683
|
-
onChange: (v: string) => void;
|
|
684
|
-
onClear?: () => void;
|
|
685
|
-
clearable: boolean;
|
|
686
|
-
}) {
|
|
687
|
-
// Buffer the text input so intermediate hex like "#a" doesn't
|
|
688
|
-
// commit until it parses as a full color.
|
|
689
|
-
const [draft, setDraft] = useState(value);
|
|
690
|
-
const tColor = useLocale();
|
|
691
|
-
useEffect(() => setDraft(value), [value]);
|
|
692
|
-
|
|
693
|
-
const commitHex = (hex: string) => {
|
|
694
|
-
if (/^#[0-9a-fA-F]{6}$/.test(hex)) onChange(hex);
|
|
695
|
-
};
|
|
696
|
-
|
|
697
|
-
return (
|
|
698
|
-
<Field label={label}>
|
|
699
|
-
<label className="relative inline-flex size-8 shrink-0 cursor-pointer items-center justify-center overflow-hidden rounded-md border bg-background shadow-xs transition-[border-color,scale] duration-150 hover:border-foreground/20 active:scale-[0.96] has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-ring/40">
|
|
700
|
-
<span
|
|
701
|
-
className="size-5 rounded-sm"
|
|
702
|
-
style={{
|
|
703
|
-
backgroundColor: dim ? 'transparent' : value,
|
|
704
|
-
backgroundImage: dim
|
|
705
|
-
? 'linear-gradient(45deg, #d4d4d4 25%, transparent 25%, transparent 75%, #d4d4d4 75%), linear-gradient(45deg, #d4d4d4 25%, transparent 25%, transparent 75%, #d4d4d4 75%)'
|
|
706
|
-
: undefined,
|
|
707
|
-
backgroundSize: dim ? '8px 8px' : undefined,
|
|
708
|
-
backgroundPosition: dim ? '0 0, 4px 4px' : undefined,
|
|
709
|
-
}}
|
|
710
|
-
/>
|
|
711
|
-
<input
|
|
712
|
-
type="color"
|
|
713
|
-
value={value}
|
|
714
|
-
onChange={(e) => {
|
|
715
|
-
setDraft(e.target.value);
|
|
716
|
-
onChange(e.target.value);
|
|
717
|
-
}}
|
|
718
|
-
className="absolute inset-0 cursor-pointer opacity-0"
|
|
719
|
-
/>
|
|
720
|
-
</label>
|
|
721
|
-
<Input
|
|
722
|
-
type="text"
|
|
723
|
-
value={draft}
|
|
724
|
-
onChange={(e) => {
|
|
725
|
-
setDraft(e.target.value);
|
|
726
|
-
commitHex(e.target.value);
|
|
727
|
-
}}
|
|
728
|
-
className="nums h-8 flex-1 font-mono text-[11px] uppercase"
|
|
729
|
-
spellCheck={false}
|
|
730
|
-
/>
|
|
731
|
-
{clearable && onClear && (
|
|
732
|
-
<Button
|
|
733
|
-
variant="ghost"
|
|
734
|
-
size="icon"
|
|
735
|
-
className="size-8 text-muted-foreground hover:text-foreground"
|
|
736
|
-
onClick={onClear}
|
|
737
|
-
aria-label={tColor.inspector.clearAria}
|
|
738
|
-
>
|
|
739
|
-
<X className="size-3.5" />
|
|
740
|
-
</Button>
|
|
741
|
-
)}
|
|
742
|
-
</Field>
|
|
733
|
+
<ToggleGroup
|
|
734
|
+
size="sm"
|
|
735
|
+
variant="outline"
|
|
736
|
+
value={[snapshot.textAlign]}
|
|
737
|
+
onValueChange={(value) => {
|
|
738
|
+
const next = value[0];
|
|
739
|
+
if (!next) return;
|
|
740
|
+
apply([{ kind: 'set-style', key: 'textAlign', value: next === 'left' ? null : next }]);
|
|
741
|
+
}}
|
|
742
|
+
aria-label={t.inspector.alignLabel}
|
|
743
|
+
>
|
|
744
|
+
{ALIGN_OPTIONS.map(({ v, icon: Icon }) => (
|
|
745
|
+
<ToggleGroupItem key={v} value={v} aria-label={v} title={v} className="size-7 px-0">
|
|
746
|
+
<Icon />
|
|
747
|
+
</ToggleGroupItem>
|
|
748
|
+
))}
|
|
749
|
+
</ToggleGroup>
|
|
743
750
|
);
|
|
744
751
|
}
|
|
745
752
|
|
|
@@ -748,7 +755,7 @@ function ImageField({ src, anchor }: { src: string; anchor: HTMLElement }) {
|
|
|
748
755
|
const { openCrop, openReplace } = useInspector();
|
|
749
756
|
const isImage = anchor.tagName === 'IMG';
|
|
750
757
|
return (
|
|
751
|
-
<div className="
|
|
758
|
+
<div className="flex flex-col gap-2">
|
|
752
759
|
<div className="flex items-center gap-3">
|
|
753
760
|
<div className="flex size-14 shrink-0 items-center justify-center overflow-hidden rounded-md border bg-[repeating-conic-gradient(theme(colors.muted)_0_25%,transparent_0_50%)] bg-[length:8px_8px]">
|
|
754
761
|
<img
|
|
@@ -807,7 +814,7 @@ function PlaceholderField({
|
|
|
807
814
|
const [submitting, setSubmitting] = useState(false);
|
|
808
815
|
const t = useLocale();
|
|
809
816
|
return (
|
|
810
|
-
<div className="
|
|
817
|
+
<div className="flex flex-col gap-2">
|
|
811
818
|
<p className="text-[11px] leading-relaxed text-muted-foreground">
|
|
812
819
|
{t.inspector.placeholderHintLabel}{' '}
|
|
813
820
|
<span className="font-medium text-foreground">{hint}</span>
|
|
@@ -916,6 +923,8 @@ function CommentsSection({
|
|
|
916
923
|
const ta = wrapRef.current?.querySelector('textarea');
|
|
917
924
|
if (!ta) return;
|
|
918
925
|
e.preventDefault();
|
|
926
|
+
const details = ta.closest('details');
|
|
927
|
+
if (details) details.open = true;
|
|
919
928
|
ta.focus({ preventScroll: true });
|
|
920
929
|
};
|
|
921
930
|
window.addEventListener('keydown', onKey);
|
|
@@ -935,38 +944,42 @@ function CommentsSection({
|
|
|
935
944
|
};
|
|
936
945
|
|
|
937
946
|
return (
|
|
938
|
-
|
|
939
|
-
<div className=
|
|
940
|
-
<
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
/>
|
|
953
|
-
</div>
|
|
954
|
-
<div className="flex items-center justify-between gap-2">
|
|
955
|
-
<span className="font-mono text-[10.5px] text-muted-foreground/70">
|
|
956
|
-
{t.inspector.commentShortcutHint}
|
|
957
|
-
</span>
|
|
958
|
-
<Button size="sm" variant="brand" disabled={submitting || !draft.trim()} onClick={submit}>
|
|
959
|
-
{t.inspector.addComment}
|
|
960
|
-
</Button>
|
|
961
|
-
</div>
|
|
947
|
+
<>
|
|
948
|
+
<div ref={wrapRef} className={cn('rounded-[6px]', showCue && 'comment-cue')}>
|
|
949
|
+
<Textarea
|
|
950
|
+
value={draft}
|
|
951
|
+
onChange={(e) => setDraft(e.target.value)}
|
|
952
|
+
onKeyDown={(e) => {
|
|
953
|
+
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
|
|
954
|
+
e.preventDefault();
|
|
955
|
+
submit();
|
|
956
|
+
}
|
|
957
|
+
}}
|
|
958
|
+
placeholder={t.inspector.commentPlaceholder}
|
|
959
|
+
className="min-h-16 resize-none text-[12px]"
|
|
960
|
+
/>
|
|
962
961
|
</div>
|
|
963
|
-
|
|
962
|
+
<div className="flex items-center justify-between gap-2">
|
|
963
|
+
<span className="font-mono text-[10.5px] text-muted-foreground/70">
|
|
964
|
+
{t.inspector.commentShortcutHint}
|
|
965
|
+
</span>
|
|
966
|
+
<Button size="sm" variant="brand" disabled={submitting || !draft.trim()} onClick={submit}>
|
|
967
|
+
{t.inspector.addComment}
|
|
968
|
+
</Button>
|
|
969
|
+
</div>
|
|
970
|
+
</>
|
|
964
971
|
);
|
|
965
972
|
}
|
|
966
973
|
|
|
967
974
|
function readSnapshot(el: HTMLElement): ElementSnapshot {
|
|
968
975
|
const cs = getComputedStyle(el);
|
|
969
|
-
const text =
|
|
976
|
+
const text =
|
|
977
|
+
el.tagName !== 'IMG' &&
|
|
978
|
+
el.dataset.slidePlaceholder === undefined &&
|
|
979
|
+
hasOnlyInlineTextChildren(el) &&
|
|
980
|
+
(el.textContent?.trim() || /^(H[1-6]|P|SPAN|LABEL|BLOCKQUOTE|LI|PRE|CODE)$/.test(el.tagName))
|
|
981
|
+
? readEditableText(el)
|
|
982
|
+
: null;
|
|
970
983
|
const imageSrc =
|
|
971
984
|
el.tagName === 'IMG'
|
|
972
985
|
? (el as HTMLImageElement).currentSrc || (el as HTMLImageElement).src || null
|
|
@@ -982,10 +995,7 @@ function readSnapshot(el: HTMLElement): ElementSnapshot {
|
|
|
982
995
|
: null;
|
|
983
996
|
|
|
984
997
|
return {
|
|
985
|
-
|
|
986
|
-
fontWeight: parseInt(cs.fontWeight, 10) || 400,
|
|
987
|
-
fontStyle: cs.fontStyle === 'italic' ? 'italic' : 'normal',
|
|
988
|
-
color: rgbToHex(cs.color) ?? '#000000',
|
|
998
|
+
...readTypography(el),
|
|
989
999
|
backgroundColor: isTransparent(cs.backgroundColor) ? null : rgbToHex(cs.backgroundColor),
|
|
990
1000
|
textAlign: normalizeTextAlign(cs.textAlign),
|
|
991
1001
|
lineHeight: parseLineHeight(cs.lineHeight, parseFloat(cs.fontSize) || 16),
|
|
@@ -996,6 +1006,16 @@ function readSnapshot(el: HTMLElement): ElementSnapshot {
|
|
|
996
1006
|
};
|
|
997
1007
|
}
|
|
998
1008
|
|
|
1009
|
+
function readTypography(el: HTMLElement) {
|
|
1010
|
+
const cs = getComputedStyle(el);
|
|
1011
|
+
return {
|
|
1012
|
+
fontSize: parseFloat(cs.fontSize) || 16,
|
|
1013
|
+
fontWeight: parseInt(cs.fontWeight, 10) || 400,
|
|
1014
|
+
fontStyle: cs.fontStyle === 'italic' ? ('italic' as const) : ('normal' as const),
|
|
1015
|
+
color: rgbToHex(cs.color) ?? '#000000',
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
|
|
999
1019
|
function readEditableText(el: HTMLElement): string {
|
|
1000
1020
|
const parts: string[] = [];
|
|
1001
1021
|
for (const child of Array.from(el.childNodes)) {
|
|
@@ -1071,19 +1091,6 @@ function parseLetterSpacing(value: string): number {
|
|
|
1071
1091
|
return Number.isFinite(n) ? round2(n) : 0;
|
|
1072
1092
|
}
|
|
1073
1093
|
|
|
1074
|
-
function findElementByLine(slideId: string, line: number, column: number): HTMLElement | null {
|
|
1075
|
-
const root = document.querySelector('[data-inspector-root]');
|
|
1076
|
-
if (!root) return null;
|
|
1077
|
-
const tagged = root.querySelector<HTMLElement>(`[data-slide-loc="${line}:${column}"]`);
|
|
1078
|
-
if (tagged) return tagged;
|
|
1079
|
-
const candidates = root.querySelectorAll<HTMLElement>('*');
|
|
1080
|
-
for (const el of candidates) {
|
|
1081
|
-
const hit = findSlideSource(el, slideId, { hostOnly: true });
|
|
1082
|
-
if (hit && hit.line === line) return hit.anchor;
|
|
1083
|
-
}
|
|
1084
|
-
return null;
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
1094
|
function useReloadCounter(): number {
|
|
1088
1095
|
const [n, setN] = useState(0);
|
|
1089
1096
|
useEffect(() => {
|