@drawback/ui 0.2.0-rc.20261201121350 → 0.2.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/dist/{i18n-BZnCrD-C.d.mts → i18n-B5Wcit0y.d.mts} +5 -16
- package/dist/index.d.mts +18 -75
- package/dist/index.mjs +114 -161
- package/dist/locales/de.d.mts +1 -1
- package/dist/locales/de.mjs +1 -0
- package/package.json +4 -4
- package/src/app/default-editor.tsx +16 -28
- package/src/components/color-picker/color-picker.tsx +4 -15
- package/src/components/color-picker/colors.ts +1 -5
- package/src/components/font-picker/font-picker.tsx +2 -9
- package/src/components/icons.tsx +1 -4
- package/src/components/primitives.tsx +1 -3
- package/src/components/style-icons.tsx +1 -2
- package/src/features/canvas-commands/canvas-commands.tsx +3 -10
- package/src/features/context-menu/context-menu.tsx +2 -7
- package/src/features/layers/layers-tree.ts +3 -12
- package/src/features/layers/layers.tsx +50 -24
- package/src/features/links/links.tsx +1 -6
- package/src/features/main-menu/canvas-properties.tsx +16 -18
- package/src/features/properties/linear-properties.tsx +1 -4
- package/src/features/properties/properties.tsx +57 -12
- package/src/features/toolbar/toolbar.tsx +19 -13
- package/src/hooks/use-latest.ts +1 -5
- package/src/lib/i18n.ts +5 -16
- package/src/lib/locales/de.ts +1 -0
- package/src/lib/plugins.tsx +1 -5
- package/src/stores/ui-context.tsx +2 -6
- package/src/styles.css +13 -0
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
EditorProvider,
|
|
5
5
|
EditorView,
|
|
6
6
|
useActiveTool,
|
|
7
|
-
useEditor,
|
|
8
7
|
useEditorValue,
|
|
9
8
|
useMode,
|
|
10
9
|
usePresentation,
|
|
@@ -90,8 +89,6 @@ export interface DefaultEditorProps {
|
|
|
90
89
|
readonly onMount?: (view: CanvasView) => void;
|
|
91
90
|
}
|
|
92
91
|
|
|
93
|
-
const THEME_BACKGROUND = { light: '#ffffff', dark: '#121212' } as const;
|
|
94
|
-
|
|
95
92
|
function Layout({
|
|
96
93
|
components = {},
|
|
97
94
|
slots = {},
|
|
@@ -103,14 +100,20 @@ function Layout({
|
|
|
103
100
|
DefaultEditorProps,
|
|
104
101
|
'components' | 'slots' | 'canvas' | 'minimapRenderers' | 'fileName' | 'onMount'
|
|
105
102
|
>): ReactNode {
|
|
106
|
-
const editor = useEditor();
|
|
107
103
|
const { t, isHidden, isOpen, setOpen, theme } = useUi();
|
|
108
104
|
const presentation = usePresentation();
|
|
109
105
|
const mode = useMode();
|
|
110
106
|
const selection = useSelection();
|
|
111
107
|
const tool = useActiveTool();
|
|
108
|
+
// A drawing tool with style options (the frame tool has none, so it shows no empty panel).
|
|
112
109
|
const drawingTool = useEditorValue(
|
|
113
|
-
(editor) =>
|
|
110
|
+
(editor) => {
|
|
111
|
+
const active = editor.tools.active();
|
|
112
|
+
return (
|
|
113
|
+
editor.elements.definitionOf(active) !== undefined &&
|
|
114
|
+
editor.styles.supportedKeys(active).length > 0
|
|
115
|
+
);
|
|
116
|
+
},
|
|
114
117
|
{
|
|
115
118
|
events: ['tool.change'],
|
|
116
119
|
},
|
|
@@ -141,7 +144,8 @@ function Layout({
|
|
|
141
144
|
...canvas,
|
|
142
145
|
// The link editor popover stands in for the badge on the selected element.
|
|
143
146
|
linkBadges: canvas?.linkBadges ?? (linkEditorShown ? 'unselected' : true),
|
|
144
|
-
|
|
147
|
+
// Dark mode inverts the scene canvases, so the white default background shows as #121212.
|
|
148
|
+
theme: canvas?.theme ?? theme,
|
|
145
149
|
...(contextMenuEnabled ? { onContextMenu } : {}),
|
|
146
150
|
}),
|
|
147
151
|
[canvas, theme, onContextMenu, contextMenuEnabled, linkEditorShown],
|
|
@@ -195,7 +199,9 @@ function Layout({
|
|
|
195
199
|
<MinimapComponent
|
|
196
200
|
{...(minimapRenderers === undefined && canvas?.renderers === undefined
|
|
197
201
|
? {}
|
|
198
|
-
: {
|
|
202
|
+
: {
|
|
203
|
+
renderers: minimapRenderers ?? canvas?.renderers,
|
|
204
|
+
})}
|
|
199
205
|
/>
|
|
200
206
|
),
|
|
201
207
|
}
|
|
@@ -210,19 +216,7 @@ function Layout({
|
|
|
210
216
|
)}
|
|
211
217
|
{slots.bottomLeft}
|
|
212
218
|
</div>
|
|
213
|
-
<div className="db-bottom-center">
|
|
214
|
-
{show('scrollToContent') && <ScrollToContent />}
|
|
215
|
-
{zen && (
|
|
216
|
-
<button
|
|
217
|
-
type="button"
|
|
218
|
-
className="db-pill"
|
|
219
|
-
data-testid="exit-zen"
|
|
220
|
-
onClick={() => editor.modes.setPresentation({ zen: false })}
|
|
221
|
-
>
|
|
222
|
-
{t('zen.exit')}
|
|
223
|
-
</button>
|
|
224
|
-
)}
|
|
225
|
-
</div>
|
|
219
|
+
<div className="db-bottom-center">{show('scrollToContent') && <ScrollToContent />}</div>
|
|
226
220
|
<div className="db-bottom-right">
|
|
227
221
|
{slots.bottomRight}
|
|
228
222
|
{!zen && show('help') && (
|
|
@@ -249,10 +243,7 @@ function Layout({
|
|
|
249
243
|
);
|
|
250
244
|
}
|
|
251
245
|
|
|
252
|
-
/**
|
|
253
|
-
* Complete editor: canvas plus the default controls inside the given container. Renders its own
|
|
254
|
-
* `EditorProvider` and `UiProvider`; every control can be hidden, replaced or extended.
|
|
255
|
-
*/
|
|
246
|
+
/** Complete editor: canvas plus default controls, each of which can be hidden or replaced. */
|
|
256
247
|
export function DefaultEditor({
|
|
257
248
|
editor,
|
|
258
249
|
theme,
|
|
@@ -314,10 +305,7 @@ export function DefaultEditor({
|
|
|
314
305
|
);
|
|
315
306
|
}
|
|
316
307
|
|
|
317
|
-
/**
|
|
318
|
-
* Scoped root element for UI components: carries the theme, direction and the `.db-editor`
|
|
319
|
-
* class all styles are scoped to. Opens the shortcut reference on `?`.
|
|
320
|
-
*/
|
|
308
|
+
/** Scoped root for UI components: theme, direction and `.db-editor`; `?` opens shortcuts. */
|
|
321
309
|
export function EditorRoot({
|
|
322
310
|
ref,
|
|
323
311
|
className,
|
|
@@ -13,10 +13,7 @@ import {
|
|
|
13
13
|
import { useUi } from '../../stores/ui-context.js';
|
|
14
14
|
import { Choice, IconButton, Popover, cx } from '../primitives.js';
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* The browser's EyeDropper (Chromium only): a magnifier that picks a color from anywhere on
|
|
18
|
-
* screen. `undefined` where unsupported, so the button is hidden there.
|
|
19
|
-
*/
|
|
16
|
+
/** Browser EyeDropper (Chromium only); `undefined` hides the button elsewhere. */
|
|
20
17
|
function eyeDropperOpener(): (() => Promise<string | undefined>) | undefined {
|
|
21
18
|
const EyeDropper: unknown =
|
|
22
19
|
typeof window === 'undefined' ? undefined : Reflect.get(window, 'EyeDropper');
|
|
@@ -55,11 +52,7 @@ export interface ColorPickerProps {
|
|
|
55
52
|
readonly onChange: (value: string) => void;
|
|
56
53
|
}
|
|
57
54
|
|
|
58
|
-
/**
|
|
59
|
-
* Excalidraw-style color picker: the color grid (keys q–t, a–g, z–b), the active color's
|
|
60
|
-
* shades (Shift+1–5; none for transparent, white and black) and a hex code input with a
|
|
61
|
-
* pipette that copies a color from the screen (EyeDropper, where the browser has it).
|
|
62
|
-
*/
|
|
55
|
+
/** Excalidraw-style picker: grid (q–t/a–g/z–b), shades (Shift+1–5), hex input, pipette. */
|
|
63
56
|
export function ColorPicker({ label, value, kind, onChange }: ColorPickerProps): ReactNode {
|
|
64
57
|
const { t } = useUi();
|
|
65
58
|
const active = familyOf(value);
|
|
@@ -103,8 +96,7 @@ export function ColorPicker({ label, value, kind, onChange }: ColorPickerProps):
|
|
|
103
96
|
}
|
|
104
97
|
});
|
|
105
98
|
|
|
106
|
-
//
|
|
107
|
-
// wherever focus is, except while typing in a text field.
|
|
99
|
+
// Picker hotkeys beat canvas shortcuts wherever focus is, except in text fields.
|
|
108
100
|
useEffect(() => {
|
|
109
101
|
const onKey = (event: globalThis.KeyboardEvent): void => onHotkey(event);
|
|
110
102
|
document.addEventListener('keydown', onKey, true);
|
|
@@ -271,10 +263,7 @@ export interface ColorFieldProps {
|
|
|
271
263
|
readonly disabled?: boolean;
|
|
272
264
|
}
|
|
273
265
|
|
|
274
|
-
/**
|
|
275
|
-
* Quick-pick swatches, then the current color as a button that opens the {@link ColorPicker}
|
|
276
|
-
* (Excalidraw's stroke and background controls).
|
|
277
|
-
*/
|
|
266
|
+
/** Quick-pick swatches plus a button that opens the {@link ColorPicker}. */
|
|
278
267
|
export function ColorField({
|
|
279
268
|
label,
|
|
280
269
|
value,
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Color palette for the color picker, laid out like Excalidraw's: a 5×3 grid of color families
|
|
3
|
-
* picked with the keys q–t / a–g / z–b, each family (except transparent, white and black) with five
|
|
4
|
-
* shades picked with Shift+1–5. Shades are the open-color scale (MIT).
|
|
5
|
-
*/
|
|
1
|
+
/** Excalidraw-style palette: 5×3 families (q–t/a–g/z–b), five open-color shades each (MIT). */
|
|
6
2
|
|
|
7
3
|
export type ShadedFamily =
|
|
8
4
|
| 'gray'
|
|
@@ -55,10 +55,7 @@ export interface FontPickerProps {
|
|
|
55
55
|
readonly onChange: (id: FontId) => void;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
/**
|
|
59
|
-
* Searchable list of every registered font, with the fonts the document uses first. Each name
|
|
60
|
-
* is drawn in its own font. Arrow keys move, Enter picks.
|
|
61
|
-
*/
|
|
58
|
+
/** Searchable font list, document fonts first, each name drawn in its own font. */
|
|
62
59
|
export function FontPicker({ value, onChange }: FontPickerProps): ReactNode {
|
|
63
60
|
const editor = useEditor();
|
|
64
61
|
const { t } = useUi();
|
|
@@ -108,7 +105,6 @@ export function FontPicker({ value, onChange }: FontPickerProps): ReactNode {
|
|
|
108
105
|
?.querySelector<HTMLElement>(`[data-index="${index}"]`)
|
|
109
106
|
?.scrollIntoView({ block: 'nearest' });
|
|
110
107
|
};
|
|
111
|
-
// Brings the current font into view when the list mounts.
|
|
112
108
|
const revealCurrent = useCallback((node: HTMLDivElement | null) => {
|
|
113
109
|
node?.scrollIntoView({ block: 'nearest' });
|
|
114
110
|
}, []);
|
|
@@ -229,10 +225,7 @@ export interface FontFamilyFieldProps {
|
|
|
229
225
|
readonly testId?: string;
|
|
230
226
|
}
|
|
231
227
|
|
|
232
|
-
/**
|
|
233
|
-
* Quick picks for the hand-drawn, normal and code fonts, then a button that opens the
|
|
234
|
-
* {@link FontPicker}. The button is highlighted while any other font is set.
|
|
235
|
-
*/
|
|
228
|
+
/** Hand/normal/code quick picks plus a {@link FontPicker} button, lit for any other font. */
|
|
236
229
|
export function FontFamilyField({ value, onChange, testId }: FontFamilyFieldProps): ReactNode {
|
|
237
230
|
const editor = useEditor();
|
|
238
231
|
const { t } = useUi();
|
package/src/components/icons.tsx
CHANGED
|
@@ -201,10 +201,7 @@ export interface IconProps {
|
|
|
201
201
|
readonly name: string;
|
|
202
202
|
/** Pixel size (default 16). */
|
|
203
203
|
readonly size?: number;
|
|
204
|
-
/**
|
|
205
|
-
* Stroke width in screen pixels (default 1), whatever the size. Lucide measures strokes on
|
|
206
|
-
* its 24-unit grid, where 1 at 16px would draw 0.67px lines that blur into grey.
|
|
207
|
-
*/
|
|
204
|
+
/** Screen-pixel stroke width (default 1); Lucide's 24-unit strokes would blur at 16px. */
|
|
208
205
|
readonly strokeWidth?: number;
|
|
209
206
|
}
|
|
210
207
|
|
|
@@ -384,9 +384,7 @@ export function Dialog({ open, onClose, title, testId, wide, children }: DialogP
|
|
|
384
384
|
|
|
385
385
|
const previous = document.activeElement as HTMLElement | null;
|
|
386
386
|
focusables(ref.current ?? document.body)[0]?.focus();
|
|
387
|
-
// Escape
|
|
388
|
-
// click, and a download can blur the page. Keys inside the dialog are handled (and stopped)
|
|
389
|
-
// by `onKeyDown` below, so this only sees keys from outside.
|
|
387
|
+
// Catch Escape outside the dialog too: Safari doesn't focus clicked buttons, downloads blur.
|
|
390
388
|
const onDocumentKey = (event: globalThis.KeyboardEvent): void => {
|
|
391
389
|
if (
|
|
392
390
|
event.key === 'Escape' &&
|
|
@@ -65,8 +65,7 @@ export const styleIcons: Readonly<Record<string, IconComponent>> = {
|
|
|
65
65
|
strokeDasharray="0 4"
|
|
66
66
|
/>,
|
|
67
67
|
),
|
|
68
|
-
// Sloppiness:
|
|
69
|
-
// double stroke (after Excalidraw's icons).
|
|
68
|
+
// Sloppiness icons after Excalidraw's: clean, offset double, and wobbly double stroke.
|
|
70
69
|
sloppinessArchitect: svg(
|
|
71
70
|
<path
|
|
72
71
|
d="M2.5 13.5c2.5-1 4.5-5 7-5s2.5 3 4 3 2.5-1.5 4-3"
|
|
@@ -17,19 +17,13 @@ function reportError(editor: AnyEditor, error: unknown, context: string): void {
|
|
|
17
17
|
editor.events.reportError(toError(error), context);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
/**
|
|
21
|
-
* Registers the UI-level commands the context menu and shortcuts use: copy as PNG
|
|
22
|
-
* (Shift+Alt+C) / SVG, copy link to object (with a short confirmation), the minimap toggle and opening the canvas settings in the main menu (Alt+/).
|
|
23
|
-
* `<DefaultEditor>` renders it; custom layouts can render it too.
|
|
24
|
-
*/
|
|
20
|
+
/** Registers UI commands (copy as image, copy link, minimap, canvas settings). */
|
|
25
21
|
export function CanvasCommands(): ReactNode {
|
|
26
22
|
const editor = useEditor();
|
|
27
|
-
// A short confirmation after copying, e.g. "Link copied".
|
|
28
23
|
const [notice, setNotice] = useState<string | undefined>(undefined);
|
|
29
24
|
const view = useCanvasView();
|
|
30
25
|
const { t, isOpen, setOpen, isHidden } = useUi();
|
|
31
|
-
//
|
|
32
|
-
// events: `canRun` is also called while rendering (e.g. by `useCommand`).
|
|
26
|
+
// Not effect events: `canRun` also runs during render.
|
|
33
27
|
const latest = useLatest({ view, isOpen, setOpen, isHidden });
|
|
34
28
|
const latestView = () => latest.current.view;
|
|
35
29
|
const panels = () => latest.current;
|
|
@@ -49,8 +43,7 @@ export function CanvasCommands(): ReactNode {
|
|
|
49
43
|
bounds: editor.selection.get().length > 0 ? 'selection' : 'content',
|
|
50
44
|
padding: 10,
|
|
51
45
|
});
|
|
52
|
-
//
|
|
53
|
-
// user gesture while the image renders.
|
|
46
|
+
// A promise keeps Safari's clipboard write inside the user gesture.
|
|
54
47
|
const type = format === 'png' ? 'image/png' : 'text/plain';
|
|
55
48
|
const blob = exported.then((result) => {
|
|
56
49
|
if (format === 'svg') {
|
|
@@ -71,11 +71,7 @@ export interface BuiltinContextMenuState {
|
|
|
71
71
|
isOpen(panel: PanelId): boolean;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
/**
|
|
75
|
-
* Built-in context menu entries, in Excalidraw's order; `t` resolves labels at render time.
|
|
76
|
-
* On an element: clipboard, copy as image, styles, grouping, stacking, flipping, link /
|
|
77
|
-
* duplicate / lock, delete. On the canvas: paste, copy as image, select all, view toggles.
|
|
78
|
-
*/
|
|
74
|
+
/** Built-in context menu entries in Excalidraw's order; `t` resolves labels at render time. */
|
|
79
75
|
export function builtinContextMenuItems(
|
|
80
76
|
t: Translate,
|
|
81
77
|
ui?: BuiltinContextMenuState,
|
|
@@ -272,8 +268,7 @@ export function ContextMenu(): ReactNode {
|
|
|
272
268
|
Math.min(contextMenu.clientY - container.top, container.height - menu.height - 4),
|
|
273
269
|
),
|
|
274
270
|
});
|
|
275
|
-
// Focus the menu
|
|
276
|
-
// Home and End move into the items from here.
|
|
271
|
+
// Focus the menu, not an item, so nothing looks pre-selected.
|
|
277
272
|
ref.current.focus({ preventScroll: true });
|
|
278
273
|
}, [contextMenu, portalContainer, entries.length]);
|
|
279
274
|
|
|
@@ -80,10 +80,7 @@ export const layerKey = (id: LayerId): string => `layer:${id}`;
|
|
|
80
80
|
export const groupKey = (layerId: LayerId, id: GroupId): string => `group:${layerId}:${id}`;
|
|
81
81
|
export const elementKey = (id: ElementId): string => `element:${id}`;
|
|
82
82
|
|
|
83
|
-
/**
|
|
84
|
-
* Flattens layers (top layer first), groups and elements (topmost first) into visible rows.
|
|
85
|
-
* A group appears in each layer that holds some of its members, at its topmost member.
|
|
86
|
-
*/
|
|
83
|
+
/** Visible rows, topmost first; a group shows in each layer at its topmost member. */
|
|
87
84
|
export function buildLayerRows(source: LayerTreeSource, options: BuildOptions): TreeRow[] {
|
|
88
85
|
const query = options.query?.trim().toLowerCase() ?? '';
|
|
89
86
|
const filtering = query !== '' || options.type !== undefined;
|
|
@@ -202,10 +199,7 @@ export interface ActiveGuide {
|
|
|
202
199
|
readonly end: number;
|
|
203
200
|
}
|
|
204
201
|
|
|
205
|
-
/**
|
|
206
|
-
* The indent guide to emphasize for the row at `anchor`: its own children when it is expanded,
|
|
207
|
-
* otherwise its siblings under the parent row. `end` is exclusive.
|
|
208
|
-
*/
|
|
202
|
+
/** Indent guide at `anchor`: its children if expanded, else its siblings (`end` exclusive). */
|
|
209
203
|
export function activeGuide(rows: readonly TreeRow[], anchor: number): ActiveGuide | undefined {
|
|
210
204
|
const row = rows[anchor];
|
|
211
205
|
|
|
@@ -242,10 +236,7 @@ export interface StickyRow {
|
|
|
242
236
|
readonly top: number;
|
|
243
237
|
}
|
|
244
238
|
|
|
245
|
-
/**
|
|
246
|
-
* Expanded layer rows pinned to the top of the viewport while their contents scroll past,
|
|
247
|
-
* outermost first. `padding` is the space above the first row.
|
|
248
|
-
*/
|
|
239
|
+
/** Expanded layer rows pinned while their contents scroll; `padding` is the space above. */
|
|
249
240
|
export function stickyRows(
|
|
250
241
|
rows: readonly TreeRow[],
|
|
251
242
|
scrollTop: number,
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
activeGuide,
|
|
20
20
|
buildLayerRows,
|
|
21
21
|
editorTreeSource,
|
|
22
|
+
layerKey,
|
|
22
23
|
stickyRows,
|
|
23
24
|
visibleRange,
|
|
24
25
|
type TreeRow,
|
|
@@ -121,6 +122,20 @@ function canLock(editor: AnyEditor, row: TreeRow): boolean {
|
|
|
121
122
|
);
|
|
122
123
|
}
|
|
123
124
|
|
|
125
|
+
function canRename(editor: AnyEditor, row: TreeRow): boolean {
|
|
126
|
+
if (row.kind === 'layer') {
|
|
127
|
+
const target = { layer: row.record.id };
|
|
128
|
+
return (
|
|
129
|
+
editor.permissions.can('core.manage-layers', target) &&
|
|
130
|
+
editor.permissions.can('core.rename', target)
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return row.kind === 'group'
|
|
135
|
+
? editor.permissions.can('core.group', { group: row.record.id })
|
|
136
|
+
: editor.permissions.can('core.edit.content', row.record.id);
|
|
137
|
+
}
|
|
138
|
+
|
|
124
139
|
function toggleVisible(editor: AnyEditor, row: TreeRow): void {
|
|
125
140
|
if (row.kind === 'layer') {
|
|
126
141
|
editor.layers.setVisible(row.record.id, row.record.hidden);
|
|
@@ -157,8 +172,7 @@ function dropElements(
|
|
|
157
172
|
return;
|
|
158
173
|
}
|
|
159
174
|
|
|
160
|
-
//
|
|
161
|
-
// keys are computed up front and written in one transaction.
|
|
175
|
+
// Reads inside a transaction see the committed document, so compute everything first.
|
|
162
176
|
const wanted = new Set<ElementId>(ids);
|
|
163
177
|
const all = { includeHidden: true, includeRestricted: true } as const;
|
|
164
178
|
const moving = editor.elements.inRenderOrder(all).filter((element) => wanted.has(element.id));
|
|
@@ -259,10 +273,7 @@ export interface LayersPanelProps {
|
|
|
259
273
|
readonly onClose?: () => void;
|
|
260
274
|
}
|
|
261
275
|
|
|
262
|
-
/**
|
|
263
|
-
* Layers, groups and elements as a virtualized tree: selection sync, rename, visibility and
|
|
264
|
-
* lock toggles, search, drag-and-drop reordering and moving between layers.
|
|
265
|
-
*/
|
|
276
|
+
/** Virtualized layers tree with rename, toggles, search and drag-and-drop. */
|
|
266
277
|
export function LayersPanel({ thumbnails = false, onClose }: LayersPanelProps): ReactNode {
|
|
267
278
|
const editor = useEditor();
|
|
268
279
|
const { t, openContextMenu, isHidden } = useUi();
|
|
@@ -399,7 +410,10 @@ export function LayersPanel({ thumbnails = false, onClose }: LayersPanelProps):
|
|
|
399
410
|
|
|
400
411
|
if (event.key === 'F2') {
|
|
401
412
|
event.preventDefault();
|
|
402
|
-
|
|
413
|
+
|
|
414
|
+
if (canRename(editor, row)) {
|
|
415
|
+
setEditing(row.key);
|
|
416
|
+
}
|
|
403
417
|
} else if (event.key === 'Enter' || event.key === ' ') {
|
|
404
418
|
event.preventDefault();
|
|
405
419
|
select(row, event);
|
|
@@ -458,12 +472,7 @@ export function LayersPanel({ thumbnails = false, onClose }: LayersPanelProps):
|
|
|
458
472
|
const canDrop = (row: TreeRow): boolean =>
|
|
459
473
|
drag.current !== undefined && (drag.current.kind === 'elements' || row.kind === 'layer');
|
|
460
474
|
|
|
461
|
-
/**
|
|
462
|
-
* The drop target under the pointer, from its offset in the list: the gap between two rows
|
|
463
|
-
* counts as the lower part of the row above, so moving across rows or their children never
|
|
464
|
-
* clears the indicator. Pinned layer rows take drops themselves, and the empty space below
|
|
465
|
-
* the rows moves a layer to the bottom of the root.
|
|
466
|
-
*/
|
|
475
|
+
/** Drop target at a list offset; gaps count as the row above so the indicator never clears. */
|
|
467
476
|
const dropTargetAt = (event: DragEvent<HTMLDivElement>): DropTarget | undefined => {
|
|
468
477
|
const list = listRef.current;
|
|
469
478
|
const content = contentRef.current;
|
|
@@ -557,14 +566,7 @@ export function LayersPanel({ thumbnails = false, onClose }: LayersPanelProps):
|
|
|
557
566
|
paddingInlineStart: ROW_PADDING + row.depth * INDENT,
|
|
558
567
|
['--db-row-indent' as string]: `${ROW_PADDING + row.depth * INDENT}px`,
|
|
559
568
|
}}
|
|
560
|
-
title={
|
|
561
|
-
reorderable
|
|
562
|
-
? undefined
|
|
563
|
-
: editor.permissions.explain(
|
|
564
|
-
row.kind === 'layer' ? 'core.manage-layers' : 'core.reorder',
|
|
565
|
-
row.kind === 'layer' ? { layer: row.record.id } : ids[0],
|
|
566
|
-
).reason
|
|
567
|
-
}
|
|
569
|
+
title={name}
|
|
568
570
|
draggable={reorderable && editing !== row.key}
|
|
569
571
|
onClick={(event) => {
|
|
570
572
|
select(row, event);
|
|
@@ -573,7 +575,11 @@ export function LayersPanel({ thumbnails = false, onClose }: LayersPanelProps):
|
|
|
573
575
|
listRef.current.scrollTop = TREE_PADDING + (index - row.depth) * ROW_STRIDE;
|
|
574
576
|
}
|
|
575
577
|
}}
|
|
576
|
-
onDoubleClick={() =>
|
|
578
|
+
onDoubleClick={() => {
|
|
579
|
+
if (canRename(editor, row)) {
|
|
580
|
+
setEditing(row.key);
|
|
581
|
+
}
|
|
582
|
+
}}
|
|
577
583
|
onKeyDown={(event) => onRowKeyDown(row, event)}
|
|
578
584
|
onContextMenu={(event) => {
|
|
579
585
|
event.preventDefault();
|
|
@@ -680,6 +686,17 @@ export function LayersPanel({ thumbnails = false, onClose }: LayersPanelProps):
|
|
|
680
686
|
onClick={(event) => event.stopPropagation()}
|
|
681
687
|
onDoubleClick={(event) => event.stopPropagation()}
|
|
682
688
|
>
|
|
689
|
+
{row.kind === 'layer' && !isHidden('layers:add') && (
|
|
690
|
+
<IconButton
|
|
691
|
+
icon="add"
|
|
692
|
+
label={t('layers.addChild')}
|
|
693
|
+
disabled={!editor.permissions.can('core.manage-layers', { layer: row.record.id })}
|
|
694
|
+
onClick={() => addLayer(row.record.id)}
|
|
695
|
+
className="db-row-action"
|
|
696
|
+
tabIndex={-1}
|
|
697
|
+
testId={`layer-add-${row.record.id}`}
|
|
698
|
+
/>
|
|
699
|
+
)}
|
|
683
700
|
{row.kind !== 'group' && (
|
|
684
701
|
<IconButton
|
|
685
702
|
icon={isHiddenRow(row) ? 'eyeOff' : 'eye'}
|
|
@@ -705,11 +722,20 @@ export function LayersPanel({ thumbnails = false, onClose }: LayersPanelProps):
|
|
|
705
722
|
);
|
|
706
723
|
};
|
|
707
724
|
|
|
708
|
-
const addLayer = (): void => {
|
|
725
|
+
const addLayer = (parentId?: LayerId): void => {
|
|
709
726
|
const id = editor.layers.create({
|
|
710
727
|
name: t('layers.newName', { number: editor.layers.list().length + 1 }),
|
|
728
|
+
...(parentId === undefined ? {} : { parentId }),
|
|
711
729
|
});
|
|
712
730
|
editor.layers.setActive(id);
|
|
731
|
+
|
|
732
|
+
if (parentId !== undefined) {
|
|
733
|
+
setCollapsed((current) => {
|
|
734
|
+
const next = new Set(current);
|
|
735
|
+
next.delete(layerKey(parentId));
|
|
736
|
+
return next;
|
|
737
|
+
});
|
|
738
|
+
}
|
|
713
739
|
};
|
|
714
740
|
|
|
715
741
|
return (
|
|
@@ -724,7 +750,7 @@ export function LayersPanel({ thumbnails = false, onClose }: LayersPanelProps):
|
|
|
724
750
|
<IconButton
|
|
725
751
|
icon="add"
|
|
726
752
|
label={t('layers.add')}
|
|
727
|
-
onClick={addLayer}
|
|
753
|
+
onClick={() => addLayer()}
|
|
728
754
|
testId="layers-add"
|
|
729
755
|
disabled={!editor.permissions.can('core.manage-layers')}
|
|
730
756
|
/>
|
|
@@ -104,12 +104,7 @@ function LinkInput({
|
|
|
104
104
|
);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
/**
|
|
108
|
-
* Excalidraw-style link editor: a popover above the single selected element. It shows the
|
|
109
|
-
* element's link (click to open) with edit and remove buttons, or an input while editing
|
|
110
|
-
* (Mod+K, "Edit link…" in the context menu, the properties action). Enter or clicking away
|
|
111
|
-
* saves, Escape cancels, an empty link removes it.
|
|
112
|
-
*/
|
|
107
|
+
/** Excalidraw-style link editor popover above the single selected element. */
|
|
113
108
|
export function LinkEditor(): ReactNode {
|
|
114
109
|
const editor = useEditor();
|
|
115
110
|
const { t, isOpen, setOpen } = useUi();
|
|
@@ -86,24 +86,22 @@ export function CanvasPropertiesPanel(): ReactNode {
|
|
|
86
86
|
}}
|
|
87
87
|
/>
|
|
88
88
|
</label>
|
|
89
|
-
|
|
90
|
-
<
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
</label>
|
|
106
|
-
)}
|
|
89
|
+
<label className="db-field">
|
|
90
|
+
<span>{t('grid.majorEvery')}</span>
|
|
91
|
+
<input
|
|
92
|
+
type="number"
|
|
93
|
+
min={1}
|
|
94
|
+
max={100}
|
|
95
|
+
value={grid.config.majorEvery ?? 1}
|
|
96
|
+
disabled={!canGrid}
|
|
97
|
+
onChange={(event) => {
|
|
98
|
+
const every = Math.round(Number(event.target.value));
|
|
99
|
+
if (every >= 1 && every <= 100) {
|
|
100
|
+
editor.grid.set({ majorEvery: every });
|
|
101
|
+
}
|
|
102
|
+
}}
|
|
103
|
+
/>
|
|
104
|
+
</label>
|
|
107
105
|
<Section title={t('grid.color')}>
|
|
108
106
|
<ColorField
|
|
109
107
|
label={t('grid.color')}
|
|
@@ -50,10 +50,7 @@ function toolArrowType(props: JsonObject): ArrowType {
|
|
|
50
50
|
return props.elbowed === true ? 'elbow' : props.curved === true ? 'curved' : 'sharp';
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
/**
|
|
54
|
-
* Edges (sharp or round) and polygon closing for lines, and the arrow type for arrows. Without a
|
|
55
|
-
* selection it edits the active line or arrow tool's defaults; choices also become new defaults.
|
|
56
|
-
*/
|
|
53
|
+
/** Edge, polygon and arrow-type controls; without a selection they edit the tool defaults. */
|
|
57
54
|
export function LinearProperties(): ReactNode {
|
|
58
55
|
const editor = useEditor();
|
|
59
56
|
const { t } = useUi();
|
|
@@ -102,6 +102,21 @@ const TEXT_KEYS = new Set<StyleKey>([
|
|
|
102
102
|
'lineHeight',
|
|
103
103
|
]);
|
|
104
104
|
|
|
105
|
+
/** Style keys with their own section when there is no selection (text color only for the text tool). */
|
|
106
|
+
const TOOL_PANEL_KEYS: readonly StyleKey[] = [
|
|
107
|
+
'strokeColor',
|
|
108
|
+
'fillColor',
|
|
109
|
+
'fillStyle',
|
|
110
|
+
'strokeWidth',
|
|
111
|
+
'strokeStyle',
|
|
112
|
+
'roughness',
|
|
113
|
+
'cornerRadius',
|
|
114
|
+
'startArrowhead',
|
|
115
|
+
'fontFamily',
|
|
116
|
+
'fontSize',
|
|
117
|
+
'textAlign',
|
|
118
|
+
];
|
|
119
|
+
|
|
105
120
|
function asString(value: JsonValue | undefined): string | undefined {
|
|
106
121
|
return typeof value === 'string' ? value : undefined;
|
|
107
122
|
}
|
|
@@ -336,10 +351,7 @@ function CustomEditors({ elements }: { readonly elements: readonly ElementRecord
|
|
|
336
351
|
});
|
|
337
352
|
}
|
|
338
353
|
|
|
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
|
-
*/
|
|
354
|
+
/** Selection styles (or tool defaults), actions and custom editors; mixed values show none. */
|
|
343
355
|
export function PropertiesPanel(): ReactNode {
|
|
344
356
|
const editor = useEditor();
|
|
345
357
|
const { t } = useUi();
|
|
@@ -347,7 +359,12 @@ export function PropertiesPanel(): ReactNode {
|
|
|
347
359
|
const target = useStyleTarget();
|
|
348
360
|
const tool = useActiveTool();
|
|
349
361
|
|
|
350
|
-
|
|
362
|
+
// Without a selection only tool defaults show; skip the panel when none of them has a section.
|
|
363
|
+
if (
|
|
364
|
+
selected.length === 0 &&
|
|
365
|
+
!(tool === TEXT_TOOL && target?.keys.has('textColor') === true) &&
|
|
366
|
+
!TOOL_PANEL_KEYS.some((key) => target?.keys.has(key) === true)
|
|
367
|
+
) {
|
|
351
368
|
return null;
|
|
352
369
|
}
|
|
353
370
|
|
|
@@ -453,9 +470,21 @@ export function PropertiesPanel(): ReactNode {
|
|
|
453
470
|
label={t('properties.strokeStyle')}
|
|
454
471
|
value={asString(value('strokeStyle'))}
|
|
455
472
|
options={[
|
|
456
|
-
{
|
|
457
|
-
|
|
458
|
-
|
|
473
|
+
{
|
|
474
|
+
value: 'solid',
|
|
475
|
+
label: t('value.solid'),
|
|
476
|
+
icon: 'strokeSolid',
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
value: 'dashed',
|
|
480
|
+
label: t('value.dashed'),
|
|
481
|
+
icon: 'strokeDashed',
|
|
482
|
+
},
|
|
483
|
+
{
|
|
484
|
+
value: 'dotted',
|
|
485
|
+
label: t('value.dotted'),
|
|
486
|
+
icon: 'strokeDotted',
|
|
487
|
+
},
|
|
459
488
|
]}
|
|
460
489
|
onChange={set('strokeStyle')}
|
|
461
490
|
testId="stroke-style"
|
|
@@ -468,9 +497,21 @@ export function PropertiesPanel(): ReactNode {
|
|
|
468
497
|
label={t('properties.sloppiness')}
|
|
469
498
|
value={sloppinessOf(value('roughness'))}
|
|
470
499
|
options={[
|
|
471
|
-
{
|
|
472
|
-
|
|
473
|
-
|
|
500
|
+
{
|
|
501
|
+
value: 0,
|
|
502
|
+
label: t('value.architect'),
|
|
503
|
+
icon: 'sloppinessArchitect',
|
|
504
|
+
},
|
|
505
|
+
{
|
|
506
|
+
value: 1,
|
|
507
|
+
label: t('value.artist'),
|
|
508
|
+
icon: 'sloppinessArtist',
|
|
509
|
+
},
|
|
510
|
+
{
|
|
511
|
+
value: 2,
|
|
512
|
+
label: t('value.cartoonist'),
|
|
513
|
+
icon: 'sloppinessCartoonist',
|
|
514
|
+
},
|
|
474
515
|
]}
|
|
475
516
|
onChange={set('roughness')}
|
|
476
517
|
testId="sloppiness"
|
|
@@ -550,7 +591,11 @@ export function PropertiesPanel(): ReactNode {
|
|
|
550
591
|
value={asString(value('textAlign'))}
|
|
551
592
|
options={[
|
|
552
593
|
{ value: 'left', label: t('value.left'), icon: 'textLeft' },
|
|
553
|
-
{
|
|
594
|
+
{
|
|
595
|
+
value: 'center',
|
|
596
|
+
label: t('value.center'),
|
|
597
|
+
icon: 'textCenter',
|
|
598
|
+
},
|
|
554
599
|
{ value: 'right', label: t('value.right'), icon: 'textRight' },
|
|
555
600
|
]}
|
|
556
601
|
onChange={set('textAlign')}
|