@drawback/ui 0.0.0-stage → 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/README.md +22 -2
- package/dist/i18n-BZnCrD-C.d.mts +265 -0
- package/dist/index.d.mts +588 -0
- package/dist/index.mjs +4821 -0
- package/dist/locales/de.d.mts +3 -0
- package/dist/locales/de.mjs +231 -0
- package/package.json +69 -4
- package/src/app/default-editor.tsx +371 -0
- package/src/components/color-picker/color-picker.tsx +341 -0
- package/src/components/color-picker/colors.ts +135 -0
- package/src/components/font-picker/font-picker.tsx +298 -0
- package/src/components/icons.tsx +222 -0
- package/src/components/primitives.tsx +565 -0
- package/src/components/style-icons.tsx +172 -0
- package/src/features/canvas-commands/canvas-commands.tsx +173 -0
- package/src/features/context-menu/context-menu.tsx +354 -0
- package/src/features/controls/controls.tsx +281 -0
- package/src/features/export/export-dialog.tsx +164 -0
- package/src/features/layers/layers-tree.ts +335 -0
- package/src/features/layers/layers.tsx +858 -0
- package/src/features/links/links.tsx +268 -0
- package/src/features/main-menu/canvas-properties.tsx +121 -0
- package/src/features/main-menu/main-menu.tsx +215 -0
- package/src/features/minimap/minimap.tsx +69 -0
- package/src/features/properties/linear-properties.tsx +169 -0
- package/src/features/properties/properties.tsx +573 -0
- package/src/features/shortcuts/shortcuts-dialog.tsx +120 -0
- package/src/features/toolbar/toolbar.tsx +216 -0
- package/src/hooks/use-latest.ts +16 -0
- package/src/index.ts +138 -0
- package/src/lib/commands.ts +14 -0
- package/src/lib/download.ts +8 -0
- package/src/lib/i18n.ts +350 -0
- package/src/lib/locales/de.ts +231 -0
- package/src/lib/plugins.tsx +92 -0
- package/src/lib/registry.ts +140 -0
- package/src/stores/ui-context.tsx +253 -0
- package/src/styles.css +1366 -0
|
@@ -0,0 +1,573 @@
|
|
|
1
|
+
import type { AnyEditor, ElementRecord, JsonValue, StyleKey } from '@drawback/core';
|
|
2
|
+
import {
|
|
3
|
+
deepEqual,
|
|
4
|
+
useActiveTool,
|
|
5
|
+
useCommand,
|
|
6
|
+
useEditor,
|
|
7
|
+
useEditorValue,
|
|
8
|
+
useSelectedElements,
|
|
9
|
+
useStyleSummary,
|
|
10
|
+
} from '@drawback/react';
|
|
11
|
+
import type { ReactNode } from 'react';
|
|
12
|
+
import { LinearProperties } from './linear-properties.js';
|
|
13
|
+
import { LINK_COMMAND } from '../../lib/commands.js';
|
|
14
|
+
import { useUi } from '../../stores/ui-context.js';
|
|
15
|
+
import { Choice, IconButton, Island, Section } from '../../components/primitives.js';
|
|
16
|
+
import { ColorField } from '../../components/color-picker/color-picker.js';
|
|
17
|
+
import { FILL_COLORS, STROKE_COLORS } from '../../components/color-picker/colors.js';
|
|
18
|
+
import { FontFamilyField } from '../../components/font-picker/font-picker.js';
|
|
19
|
+
|
|
20
|
+
type StyleValues = Readonly<Partial<Record<StyleKey, JsonValue | undefined>>>;
|
|
21
|
+
|
|
22
|
+
interface StyleTarget {
|
|
23
|
+
readonly keys: ReadonlySet<StyleKey>;
|
|
24
|
+
readonly values: StyleValues;
|
|
25
|
+
apply(key: StyleKey, value: JsonValue): void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function useStyleTarget(): StyleTarget | undefined {
|
|
29
|
+
const editor = useEditor();
|
|
30
|
+
const selected = useSelectedElements();
|
|
31
|
+
const summary = useStyleSummary();
|
|
32
|
+
const tool = useActiveTool();
|
|
33
|
+
const toolDefaults = useEditorValue(
|
|
34
|
+
(current) =>
|
|
35
|
+
current.elements.definitionOf(tool) === undefined
|
|
36
|
+
? undefined
|
|
37
|
+
: {
|
|
38
|
+
keys: current.styles.supportedKeys(tool),
|
|
39
|
+
values: current.styles.defaults({ tool }),
|
|
40
|
+
},
|
|
41
|
+
{ events: ['tool.change', 'style.defaults.change'], equals: deepEqual },
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
if (selected.length > 0) {
|
|
45
|
+
const keys = new Set<StyleKey>();
|
|
46
|
+
const values: Partial<Record<StyleKey, JsonValue | undefined>> = {};
|
|
47
|
+
|
|
48
|
+
for (const [key, entry] of Object.entries(summary.keys) as [
|
|
49
|
+
StyleKey,
|
|
50
|
+
(typeof summary.keys)[StyleKey],
|
|
51
|
+
][]) {
|
|
52
|
+
if (entry.state === 'unsupported') {
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
keys.add(key);
|
|
57
|
+
values[key] = entry.state === 'uniform' ? entry.value : undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
keys,
|
|
62
|
+
values,
|
|
63
|
+
apply: (key, value) => {
|
|
64
|
+
editor.styles.apply(editor.selection.get(), { [key]: value });
|
|
65
|
+
stickToolDefaults(editor, key, value);
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (toolDefaults === undefined) {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
keys: new Set(toolDefaults.keys),
|
|
76
|
+
values: toolDefaults.values as unknown as StyleValues,
|
|
77
|
+
apply: (key, value) => stickToolDefaults(editor, key, value),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function stickToolDefaults(editor: AnyEditor, key: StyleKey, value: JsonValue): void {
|
|
82
|
+
for (const { id } of editor.tools.list()) {
|
|
83
|
+
if (
|
|
84
|
+
editor.elements.definitionOf(id) !== undefined &&
|
|
85
|
+
editor.styles.supportedKeys(id).includes(key)
|
|
86
|
+
) {
|
|
87
|
+
editor.styles.setDefaults({ [key]: value }, { tool: id });
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const TEXT_TOOL = 'core.text';
|
|
93
|
+
|
|
94
|
+
const TEXT_KEYS = new Set<StyleKey>([
|
|
95
|
+
'fontFamily',
|
|
96
|
+
'fontSize',
|
|
97
|
+
'fontWeight',
|
|
98
|
+
'fontStyle',
|
|
99
|
+
'textAlign',
|
|
100
|
+
'verticalAlign',
|
|
101
|
+
'textColor',
|
|
102
|
+
'lineHeight',
|
|
103
|
+
]);
|
|
104
|
+
|
|
105
|
+
function asString(value: JsonValue | undefined): string | undefined {
|
|
106
|
+
return typeof value === 'string' ? value : undefined;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function sloppinessOf(value: JsonValue | undefined): number | undefined {
|
|
110
|
+
return typeof value === 'number' ? Math.min(2, Math.max(0, Math.round(value))) : undefined;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function asNumber(value: JsonValue | undefined): number | undefined {
|
|
114
|
+
return typeof value === 'number' ? value : undefined;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function OpacityField({ elements }: { readonly elements: readonly ElementRecord[] }): ReactNode {
|
|
118
|
+
const editor = useEditor();
|
|
119
|
+
const { t } = useUi();
|
|
120
|
+
const values = new Set(elements.map((element) => element.opacity));
|
|
121
|
+
// Every change commits right away, so the slider shows the elements' opacity directly.
|
|
122
|
+
const value = values.size === 1 ? Math.round((elements[0]?.opacity ?? 1) * 100) : undefined;
|
|
123
|
+
|
|
124
|
+
const commit = (next: number): void => {
|
|
125
|
+
const opacity = Math.max(0, Math.min(1, next / 100));
|
|
126
|
+
editor.transact(
|
|
127
|
+
(transaction) => {
|
|
128
|
+
for (const element of elements) {
|
|
129
|
+
transaction.elements.update(element.id, { opacity });
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
{ label: 'Change opacity', mergeKey: 'ui.opacity' },
|
|
133
|
+
);
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
return (
|
|
137
|
+
<label className="nx-range">
|
|
138
|
+
<input
|
|
139
|
+
type="range"
|
|
140
|
+
min={0}
|
|
141
|
+
max={100}
|
|
142
|
+
step={10}
|
|
143
|
+
value={value ?? 100}
|
|
144
|
+
aria-label={t('properties.opacity')}
|
|
145
|
+
data-testid="opacity"
|
|
146
|
+
onChange={(event) => commit(Number(event.target.value))}
|
|
147
|
+
/>
|
|
148
|
+
<span>{value === undefined ? t('properties.mixed') : `${value}%`}</span>
|
|
149
|
+
</label>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function ActionButton({
|
|
154
|
+
command,
|
|
155
|
+
icon,
|
|
156
|
+
label,
|
|
157
|
+
args,
|
|
158
|
+
}: {
|
|
159
|
+
readonly command: string;
|
|
160
|
+
readonly icon: string;
|
|
161
|
+
readonly label: string;
|
|
162
|
+
readonly args?: unknown;
|
|
163
|
+
}): ReactNode {
|
|
164
|
+
const state = useCommand(command, args);
|
|
165
|
+
return (
|
|
166
|
+
<IconButton
|
|
167
|
+
icon={icon}
|
|
168
|
+
label={label}
|
|
169
|
+
shortcut={state.shortcuts}
|
|
170
|
+
disabled={!state.enabled}
|
|
171
|
+
onClick={() => state.run(args)}
|
|
172
|
+
testId={`action-${command}${args === undefined ? '' : `-${JSON.stringify(args).replace(/\W+/g, '')}`}`}
|
|
173
|
+
/>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function ElementActions({ count }: { readonly count: number }): ReactNode {
|
|
178
|
+
const { t } = useUi();
|
|
179
|
+
return (
|
|
180
|
+
<>
|
|
181
|
+
<Section title={t('properties.layers')}>
|
|
182
|
+
<div className="nx-row">
|
|
183
|
+
<ActionButton
|
|
184
|
+
command="core.sendToBack"
|
|
185
|
+
icon="sendToBack"
|
|
186
|
+
label={t('action.sendToBack')}
|
|
187
|
+
/>
|
|
188
|
+
<ActionButton
|
|
189
|
+
command="core.sendBackward"
|
|
190
|
+
icon="sendBackward"
|
|
191
|
+
label={t('action.sendBackward')}
|
|
192
|
+
/>
|
|
193
|
+
<ActionButton
|
|
194
|
+
command="core.bringForward"
|
|
195
|
+
icon="bringForward"
|
|
196
|
+
label={t('action.bringForward')}
|
|
197
|
+
/>
|
|
198
|
+
<ActionButton
|
|
199
|
+
command="core.bringToFront"
|
|
200
|
+
icon="bringToFront"
|
|
201
|
+
label={t('action.bringToFront')}
|
|
202
|
+
/>
|
|
203
|
+
</div>
|
|
204
|
+
</Section>
|
|
205
|
+
{count > 1 && (
|
|
206
|
+
<Section title={t('properties.align')}>
|
|
207
|
+
<div className="nx-row nx-wrap">
|
|
208
|
+
<ActionButton
|
|
209
|
+
command="core.align"
|
|
210
|
+
args={{ edge: 'left' }}
|
|
211
|
+
icon="alignLeft"
|
|
212
|
+
label={t('action.alignLeft')}
|
|
213
|
+
/>
|
|
214
|
+
<ActionButton
|
|
215
|
+
command="core.align"
|
|
216
|
+
args={{ edge: 'center' }}
|
|
217
|
+
icon="alignCenter"
|
|
218
|
+
label={t('action.alignCenter')}
|
|
219
|
+
/>
|
|
220
|
+
<ActionButton
|
|
221
|
+
command="core.align"
|
|
222
|
+
args={{ edge: 'right' }}
|
|
223
|
+
icon="alignRight"
|
|
224
|
+
label={t('action.alignRight')}
|
|
225
|
+
/>
|
|
226
|
+
<ActionButton
|
|
227
|
+
command="core.align"
|
|
228
|
+
args={{ edge: 'top' }}
|
|
229
|
+
icon="alignTop"
|
|
230
|
+
label={t('action.alignTop')}
|
|
231
|
+
/>
|
|
232
|
+
<ActionButton
|
|
233
|
+
command="core.align"
|
|
234
|
+
args={{ edge: 'middle' }}
|
|
235
|
+
icon="alignMiddle"
|
|
236
|
+
label={t('action.alignMiddle')}
|
|
237
|
+
/>
|
|
238
|
+
<ActionButton
|
|
239
|
+
command="core.align"
|
|
240
|
+
args={{ edge: 'bottom' }}
|
|
241
|
+
icon="alignBottom"
|
|
242
|
+
label={t('action.alignBottom')}
|
|
243
|
+
/>
|
|
244
|
+
{count > 2 && (
|
|
245
|
+
<>
|
|
246
|
+
<ActionButton
|
|
247
|
+
command="core.distribute"
|
|
248
|
+
args={{ axis: 'horizontal' }}
|
|
249
|
+
icon="distributeHorizontal"
|
|
250
|
+
label={t('action.distributeHorizontal')}
|
|
251
|
+
/>
|
|
252
|
+
<ActionButton
|
|
253
|
+
command="core.distribute"
|
|
254
|
+
args={{ axis: 'vertical' }}
|
|
255
|
+
icon="distributeVertical"
|
|
256
|
+
label={t('action.distributeVertical')}
|
|
257
|
+
/>
|
|
258
|
+
</>
|
|
259
|
+
)}
|
|
260
|
+
</div>
|
|
261
|
+
</Section>
|
|
262
|
+
)}
|
|
263
|
+
<Section title={t('properties.actions')}>
|
|
264
|
+
<div className="nx-row nx-wrap">
|
|
265
|
+
<ActionButton
|
|
266
|
+
command="core.duplicate"
|
|
267
|
+
icon="copy"
|
|
268
|
+
label={t('action.duplicate')}
|
|
269
|
+
/>
|
|
270
|
+
<ActionButton
|
|
271
|
+
command="core.delete"
|
|
272
|
+
icon="delete"
|
|
273
|
+
label={t('action.delete')}
|
|
274
|
+
/>
|
|
275
|
+
<ActionButton
|
|
276
|
+
command="core.group"
|
|
277
|
+
icon="group"
|
|
278
|
+
label={t('action.group')}
|
|
279
|
+
/>
|
|
280
|
+
<ActionButton
|
|
281
|
+
command="core.ungroup"
|
|
282
|
+
icon="ungroup"
|
|
283
|
+
label={t('action.ungroup')}
|
|
284
|
+
/>
|
|
285
|
+
<ActionButton
|
|
286
|
+
command="core.flipHorizontal"
|
|
287
|
+
icon="flipHorizontal"
|
|
288
|
+
label={t('action.flipHorizontal')}
|
|
289
|
+
/>
|
|
290
|
+
<ActionButton
|
|
291
|
+
command="core.flipVertical"
|
|
292
|
+
icon="flipVertical"
|
|
293
|
+
label={t('action.flipVertical')}
|
|
294
|
+
/>
|
|
295
|
+
<ActionButton
|
|
296
|
+
command="core.lock.toggle"
|
|
297
|
+
icon="lock"
|
|
298
|
+
label={t('action.lock')}
|
|
299
|
+
/>
|
|
300
|
+
{count === 1 && (
|
|
301
|
+
<ActionButton
|
|
302
|
+
command={LINK_COMMAND}
|
|
303
|
+
icon="link"
|
|
304
|
+
label={t('link.edit')}
|
|
305
|
+
/>
|
|
306
|
+
)}
|
|
307
|
+
<ActionButton
|
|
308
|
+
command="core.image.crop"
|
|
309
|
+
icon="crop"
|
|
310
|
+
label={t('action.crop')}
|
|
311
|
+
/>
|
|
312
|
+
</div>
|
|
313
|
+
</Section>
|
|
314
|
+
</>
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function CustomEditors({ elements }: { readonly elements: readonly ElementRecord[] }): ReactNode {
|
|
319
|
+
const editor = useEditor();
|
|
320
|
+
const { registry } = useUi();
|
|
321
|
+
const types = [...new Set(elements.map((element) => element.type))];
|
|
322
|
+
return types.map((type) => {
|
|
323
|
+
const Component = registry.propertyEditors.get(type);
|
|
324
|
+
return Component === undefined ? null : (
|
|
325
|
+
<div
|
|
326
|
+
key={type}
|
|
327
|
+
className="nx-custom-editor"
|
|
328
|
+
data-testid={`property-editor-${type}`}
|
|
329
|
+
>
|
|
330
|
+
<Component
|
|
331
|
+
editor={editor}
|
|
332
|
+
elements={elements.filter((element) => element.type === type)}
|
|
333
|
+
/>
|
|
334
|
+
</div>
|
|
335
|
+
);
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Styles of the selection (or of the active drawing tool's defaults), element actions and
|
|
341
|
+
* registered custom property editors. Mixed values show no selected option.
|
|
342
|
+
*/
|
|
343
|
+
export function PropertiesPanel(): ReactNode {
|
|
344
|
+
const editor = useEditor();
|
|
345
|
+
const { t } = useUi();
|
|
346
|
+
const selected = useSelectedElements();
|
|
347
|
+
const target = useStyleTarget();
|
|
348
|
+
const tool = useActiveTool();
|
|
349
|
+
|
|
350
|
+
if (target === undefined && selected.length === 0) {
|
|
351
|
+
return null;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const hasText =
|
|
355
|
+
selected.length === 0 ||
|
|
356
|
+
selected.some(
|
|
357
|
+
(element) =>
|
|
358
|
+
element.type === 'core.text' || (editor.text.layoutOf(element)?.text ?? '') !== '',
|
|
359
|
+
);
|
|
360
|
+
const has = (key: StyleKey) => target?.keys.has(key) === true && (!TEXT_KEYS.has(key) || hasText);
|
|
361
|
+
const value = (key: StyleKey) => target?.values[key];
|
|
362
|
+
const set = (key: StyleKey) => (next: JsonValue) => target?.apply(key, next);
|
|
363
|
+
const fillVisible = has('fillColor') && value('fillStyle') !== 'none';
|
|
364
|
+
|
|
365
|
+
return (
|
|
366
|
+
<Island
|
|
367
|
+
className="nx-properties"
|
|
368
|
+
label={t('properties.label')}
|
|
369
|
+
testId="properties-panel"
|
|
370
|
+
>
|
|
371
|
+
<div className="nx-scroll">
|
|
372
|
+
{selected.length > 1 && (
|
|
373
|
+
<p className="nx-caption">{t('properties.selected', { count: selected.length })}</p>
|
|
374
|
+
)}
|
|
375
|
+
{has('textColor') && (selected.length > 0 || tool === TEXT_TOOL) && (
|
|
376
|
+
<Section title={t('properties.textColor')}>
|
|
377
|
+
<ColorField
|
|
378
|
+
label={t('properties.textColor')}
|
|
379
|
+
value={asString(value('textColor'))}
|
|
380
|
+
palette={STROKE_COLORS}
|
|
381
|
+
onChange={set('textColor')}
|
|
382
|
+
testId="text-color"
|
|
383
|
+
/>
|
|
384
|
+
</Section>
|
|
385
|
+
)}
|
|
386
|
+
{has('strokeColor') && (
|
|
387
|
+
<Section title={t('properties.stroke')}>
|
|
388
|
+
<ColorField
|
|
389
|
+
label={t('properties.stroke')}
|
|
390
|
+
value={asString(value('strokeColor'))}
|
|
391
|
+
palette={STROKE_COLORS}
|
|
392
|
+
onChange={set('strokeColor')}
|
|
393
|
+
testId="stroke-color"
|
|
394
|
+
/>
|
|
395
|
+
</Section>
|
|
396
|
+
)}
|
|
397
|
+
{has('fillColor') && (
|
|
398
|
+
<Section title={t('properties.background')}>
|
|
399
|
+
<ColorField
|
|
400
|
+
label={t('properties.background')}
|
|
401
|
+
value={value('fillStyle') === 'none' ? 'transparent' : asString(value('fillColor'))}
|
|
402
|
+
palette={FILL_COLORS}
|
|
403
|
+
kind="background"
|
|
404
|
+
onChange={(color) => {
|
|
405
|
+
if (color === 'transparent') {
|
|
406
|
+
target?.apply('fillStyle', 'none');
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
target?.apply('fillColor', color);
|
|
411
|
+
|
|
412
|
+
if (value('fillStyle') === 'none') {
|
|
413
|
+
target?.apply('fillStyle', 'solid');
|
|
414
|
+
}
|
|
415
|
+
}}
|
|
416
|
+
testId="fill-color"
|
|
417
|
+
/>
|
|
418
|
+
</Section>
|
|
419
|
+
)}
|
|
420
|
+
{fillVisible && has('fillStyle') && (
|
|
421
|
+
<Section title={t('properties.fill')}>
|
|
422
|
+
<Choice
|
|
423
|
+
label={t('properties.fill')}
|
|
424
|
+
value={asString(value('fillStyle'))}
|
|
425
|
+
options={[
|
|
426
|
+
{ value: 'hachure', label: t('value.hachure') },
|
|
427
|
+
{ value: 'cross-hatch', label: t('value.cross-hatch') },
|
|
428
|
+
{ value: 'solid', label: t('value.solid') },
|
|
429
|
+
]}
|
|
430
|
+
onChange={set('fillStyle')}
|
|
431
|
+
testId="fill-style"
|
|
432
|
+
/>
|
|
433
|
+
</Section>
|
|
434
|
+
)}
|
|
435
|
+
{has('strokeWidth') && (
|
|
436
|
+
<Section title={t('properties.strokeWidth')}>
|
|
437
|
+
<Choice
|
|
438
|
+
label={t('properties.strokeWidth')}
|
|
439
|
+
value={asNumber(value('strokeWidth'))}
|
|
440
|
+
options={[
|
|
441
|
+
{ value: 1, label: t('value.thin'), icon: 'strokeThin' },
|
|
442
|
+
{ value: 2, label: t('value.medium'), icon: 'strokeMedium' },
|
|
443
|
+
{ value: 4, label: t('value.bold'), icon: 'strokeBold' },
|
|
444
|
+
]}
|
|
445
|
+
onChange={set('strokeWidth')}
|
|
446
|
+
testId="stroke-width"
|
|
447
|
+
/>
|
|
448
|
+
</Section>
|
|
449
|
+
)}
|
|
450
|
+
{has('strokeStyle') && (
|
|
451
|
+
<Section title={t('properties.strokeStyle')}>
|
|
452
|
+
<Choice
|
|
453
|
+
label={t('properties.strokeStyle')}
|
|
454
|
+
value={asString(value('strokeStyle'))}
|
|
455
|
+
options={[
|
|
456
|
+
{ value: 'solid', label: t('value.solid'), icon: 'strokeSolid' },
|
|
457
|
+
{ value: 'dashed', label: t('value.dashed'), icon: 'strokeDashed' },
|
|
458
|
+
{ value: 'dotted', label: t('value.dotted'), icon: 'strokeDotted' },
|
|
459
|
+
]}
|
|
460
|
+
onChange={set('strokeStyle')}
|
|
461
|
+
testId="stroke-style"
|
|
462
|
+
/>
|
|
463
|
+
</Section>
|
|
464
|
+
)}
|
|
465
|
+
{has('roughness') && (
|
|
466
|
+
<Section title={t('properties.sloppiness')}>
|
|
467
|
+
<Choice
|
|
468
|
+
label={t('properties.sloppiness')}
|
|
469
|
+
value={sloppinessOf(value('roughness'))}
|
|
470
|
+
options={[
|
|
471
|
+
{ value: 0, label: t('value.architect'), icon: 'sloppinessArchitect' },
|
|
472
|
+
{ value: 1, label: t('value.artist'), icon: 'sloppinessArtist' },
|
|
473
|
+
{ value: 2, label: t('value.cartoonist'), icon: 'sloppinessCartoonist' },
|
|
474
|
+
]}
|
|
475
|
+
onChange={set('roughness')}
|
|
476
|
+
testId="sloppiness"
|
|
477
|
+
/>
|
|
478
|
+
</Section>
|
|
479
|
+
)}
|
|
480
|
+
{has('cornerRadius') && (
|
|
481
|
+
<Section title={t('properties.cornerRadius')}>
|
|
482
|
+
<Choice
|
|
483
|
+
label={t('properties.cornerRadius')}
|
|
484
|
+
value={
|
|
485
|
+
asNumber(value('cornerRadius')) === undefined
|
|
486
|
+
? undefined
|
|
487
|
+
: (value('cornerRadius') as number) > 0
|
|
488
|
+
? 12
|
|
489
|
+
: 0
|
|
490
|
+
}
|
|
491
|
+
options={[
|
|
492
|
+
{ value: 0, label: t('value.sharp'), icon: 'edgeSharp' },
|
|
493
|
+
{ value: 12, label: t('value.round'), icon: 'edgeRound' },
|
|
494
|
+
]}
|
|
495
|
+
onChange={set('cornerRadius')}
|
|
496
|
+
testId="corner-radius"
|
|
497
|
+
/>
|
|
498
|
+
</Section>
|
|
499
|
+
)}
|
|
500
|
+
<LinearProperties />
|
|
501
|
+
{has('startArrowhead') && (
|
|
502
|
+
<Section title={t('properties.arrowheads')}>
|
|
503
|
+
{(['startArrowhead', 'endArrowhead'] as const).map((key) => (
|
|
504
|
+
<Choice
|
|
505
|
+
key={key}
|
|
506
|
+
label={t(`properties.${key}`)}
|
|
507
|
+
value={asString(value(key))}
|
|
508
|
+
options={[
|
|
509
|
+
{ value: 'none', label: t('value.none') },
|
|
510
|
+
{ value: 'arrow', label: t('value.arrow') },
|
|
511
|
+
{ value: 'triangle', label: t('value.triangle') },
|
|
512
|
+
{ value: 'bar', label: t('value.bar') },
|
|
513
|
+
{ value: 'circle', label: t('value.circle') },
|
|
514
|
+
]}
|
|
515
|
+
onChange={set(key)}
|
|
516
|
+
testId={key}
|
|
517
|
+
/>
|
|
518
|
+
))}
|
|
519
|
+
</Section>
|
|
520
|
+
)}
|
|
521
|
+
{has('fontFamily') && (
|
|
522
|
+
<Section title={t('properties.fontFamily')}>
|
|
523
|
+
<FontFamilyField
|
|
524
|
+
value={asString(value('fontFamily'))}
|
|
525
|
+
onChange={set('fontFamily')}
|
|
526
|
+
testId="font-family"
|
|
527
|
+
/>
|
|
528
|
+
</Section>
|
|
529
|
+
)}
|
|
530
|
+
{has('fontSize') && (
|
|
531
|
+
<Section title={t('properties.fontSize')}>
|
|
532
|
+
<Choice
|
|
533
|
+
label={t('properties.fontSize')}
|
|
534
|
+
value={asNumber(value('fontSize'))}
|
|
535
|
+
options={[
|
|
536
|
+
{ value: 16, label: t('value.small'), glyph: 'S' },
|
|
537
|
+
{ value: 20, label: t('value.medium'), glyph: 'M' },
|
|
538
|
+
{ value: 28, label: t('value.large'), glyph: 'L' },
|
|
539
|
+
{ value: 36, label: t('value.extraLarge'), glyph: 'XL' },
|
|
540
|
+
]}
|
|
541
|
+
onChange={set('fontSize')}
|
|
542
|
+
testId="font-size"
|
|
543
|
+
/>
|
|
544
|
+
</Section>
|
|
545
|
+
)}
|
|
546
|
+
{has('textAlign') && (
|
|
547
|
+
<Section title={t('properties.textAlign')}>
|
|
548
|
+
<Choice
|
|
549
|
+
label={t('properties.textAlign')}
|
|
550
|
+
value={asString(value('textAlign'))}
|
|
551
|
+
options={[
|
|
552
|
+
{ value: 'left', label: t('value.left'), icon: 'textLeft' },
|
|
553
|
+
{ value: 'center', label: t('value.center'), icon: 'textCenter' },
|
|
554
|
+
{ value: 'right', label: t('value.right'), icon: 'textRight' },
|
|
555
|
+
]}
|
|
556
|
+
onChange={set('textAlign')}
|
|
557
|
+
testId="text-align"
|
|
558
|
+
/>
|
|
559
|
+
</Section>
|
|
560
|
+
)}
|
|
561
|
+
{selected.length > 0 && (
|
|
562
|
+
<>
|
|
563
|
+
<Section title={t('properties.opacity')}>
|
|
564
|
+
<OpacityField elements={selected} />
|
|
565
|
+
</Section>
|
|
566
|
+
<ElementActions count={selected.length} />
|
|
567
|
+
<CustomEditors elements={selected} />
|
|
568
|
+
</>
|
|
569
|
+
)}
|
|
570
|
+
</div>
|
|
571
|
+
</Island>
|
|
572
|
+
);
|
|
573
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { useEditor } from '@drawback/react';
|
|
2
|
+
import { useMemo, useState, type ReactNode } from 'react';
|
|
3
|
+
import { useUi } from '../../stores/ui-context.js';
|
|
4
|
+
|
|
5
|
+
import { Dialog, formatShortcut } from '../../components/primitives.js';
|
|
6
|
+
|
|
7
|
+
const ARROWS = '←↑→↓';
|
|
8
|
+
const ARROW_KEYS = ['ArrowLeft', 'ArrowUp', 'ArrowRight', 'ArrowDown'];
|
|
9
|
+
|
|
10
|
+
/** Replaces the four arrow keys with one `←↑→↓` entry per modifier combination. */
|
|
11
|
+
function compactArrows(keys: readonly string[]): string[] {
|
|
12
|
+
const result: string[] = [];
|
|
13
|
+
|
|
14
|
+
for (const key of keys) {
|
|
15
|
+
const arrow = ARROW_KEYS.find((name) => key.endsWith(name));
|
|
16
|
+
const prefix = arrow === undefined ? '' : key.slice(0, -arrow.length);
|
|
17
|
+
|
|
18
|
+
if (arrow === undefined || !ARROW_KEYS.every((name) => keys.includes(prefix + name))) {
|
|
19
|
+
result.push(key);
|
|
20
|
+
} else if (!result.includes(prefix + ARROWS)) {
|
|
21
|
+
result.push(prefix + ARROWS);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Searchable list of tool shortcuts and keymap bindings with command labels. */
|
|
29
|
+
export function ShortcutsDialog(): ReactNode {
|
|
30
|
+
const editor = useEditor();
|
|
31
|
+
const { t, isOpen, setOpen } = useUi();
|
|
32
|
+
const [query, setQuery] = useState('');
|
|
33
|
+
const open = isOpen('shortcuts');
|
|
34
|
+
const sections = useMemo(() => {
|
|
35
|
+
if (!open) {
|
|
36
|
+
return [];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const tools = editor.tools
|
|
40
|
+
.list()
|
|
41
|
+
.filter((tool) => tool.shortcuts.length > 0)
|
|
42
|
+
.map((tool) => {
|
|
43
|
+
const translated = t(`tool.${tool.id}`);
|
|
44
|
+
return {
|
|
45
|
+
id: tool.id,
|
|
46
|
+
label: translated === `tool.${tool.id}` ? (tool.label ?? tool.id) : translated,
|
|
47
|
+
keys: tool.shortcuts,
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
const commands = new Map<string, { id: string; label: string; keys: string[] }>();
|
|
51
|
+
|
|
52
|
+
for (const binding of editor.input.keymap.list()) {
|
|
53
|
+
const label = editor.commands.label(binding.commandId);
|
|
54
|
+
|
|
55
|
+
// Tool keys are already listed per tool above.
|
|
56
|
+
if (label === undefined || binding.commandId === 'core.tool.activate') {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const entry = commands.get(binding.commandId) ?? { id: binding.commandId, label, keys: [] };
|
|
61
|
+
|
|
62
|
+
if (!entry.keys.includes(binding.shortcut)) {
|
|
63
|
+
entry.keys.push(binding.shortcut);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
commands.set(binding.commandId, entry);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const needle = query.trim().toLowerCase();
|
|
70
|
+
const filter = <Entry extends { label: string }>(entries: readonly Entry[]) =>
|
|
71
|
+
entries.filter((entry) => needle === '' || entry.label.toLowerCase().includes(needle));
|
|
72
|
+
return [
|
|
73
|
+
{ title: t('shortcuts.tools'), entries: filter(tools) },
|
|
74
|
+
{ title: t('shortcuts.commands'), entries: filter([...commands.values()]) },
|
|
75
|
+
];
|
|
76
|
+
}, [editor, open, query, t]);
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<Dialog
|
|
80
|
+
open={open}
|
|
81
|
+
onClose={() => setOpen('shortcuts', false)}
|
|
82
|
+
title={t('shortcuts.title')}
|
|
83
|
+
testId="shortcuts-dialog"
|
|
84
|
+
wide
|
|
85
|
+
>
|
|
86
|
+
<label className="nx-search">
|
|
87
|
+
<input
|
|
88
|
+
type="search"
|
|
89
|
+
placeholder={t('shortcuts.search')}
|
|
90
|
+
aria-label={t('shortcuts.search')}
|
|
91
|
+
value={query}
|
|
92
|
+
data-testid="shortcuts-search"
|
|
93
|
+
onChange={(event) => setQuery(event.target.value)}
|
|
94
|
+
/>
|
|
95
|
+
</label>
|
|
96
|
+
<div className="nx-shortcuts">
|
|
97
|
+
{sections.map((section) => (
|
|
98
|
+
<section key={section.title}>
|
|
99
|
+
<h3 className="nx-section-title">{section.title}</h3>
|
|
100
|
+
<dl>
|
|
101
|
+
{section.entries.map((entry) => (
|
|
102
|
+
<div
|
|
103
|
+
key={entry.id}
|
|
104
|
+
className="nx-shortcut-row"
|
|
105
|
+
>
|
|
106
|
+
<dt>{entry.label}</dt>
|
|
107
|
+
<dd>
|
|
108
|
+
{compactArrows(entry.keys).map((key) => (
|
|
109
|
+
<kbd key={key}>{formatShortcut(key)}</kbd>
|
|
110
|
+
))}
|
|
111
|
+
</dd>
|
|
112
|
+
</div>
|
|
113
|
+
))}
|
|
114
|
+
</dl>
|
|
115
|
+
</section>
|
|
116
|
+
))}
|
|
117
|
+
</div>
|
|
118
|
+
</Dialog>
|
|
119
|
+
);
|
|
120
|
+
}
|