@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
package/dist/index.mjs
CHANGED
|
@@ -186,6 +186,7 @@ const en = {
|
|
|
186
186
|
"layers.toggle": "Layers",
|
|
187
187
|
"layers.search": "Search",
|
|
188
188
|
"layers.add": "Add layer",
|
|
189
|
+
"layers.addChild": "Add layer inside",
|
|
189
190
|
"layers.newName": "Layer {number}",
|
|
190
191
|
"layers.show": "Show",
|
|
191
192
|
"layers.hide": "Hide",
|
|
@@ -235,10 +236,7 @@ const en = {
|
|
|
235
236
|
"minimap.toggle": "Toggle minimap",
|
|
236
237
|
"error.import": "Could not open the file: {message}"
|
|
237
238
|
};
|
|
238
|
-
/**
|
|
239
|
-
* Built-in languages, offered in the main menu's language picker under their own names.
|
|
240
|
-
* Catalogs other than English are separate chunks, loaded when a locale first needs them.
|
|
241
|
-
*/
|
|
239
|
+
/** Built-in languages; non-English catalogs are separate chunks loaded on first use. */
|
|
242
240
|
const LANGUAGES = [{
|
|
243
241
|
locale: "en",
|
|
244
242
|
name: "English"
|
|
@@ -253,10 +251,7 @@ function languageOf(locale) {
|
|
|
253
251
|
const base = locale.toLowerCase().split("-")[0];
|
|
254
252
|
return LANGUAGES.find((entry) => entry.locale === base);
|
|
255
253
|
}
|
|
256
|
-
/**
|
|
257
|
-
* Built-in catalog for a locale (`de-AT` falls back to `de`) once it has loaded, else
|
|
258
|
-
* `undefined` (always for English). See {@link loadMessages}.
|
|
259
|
-
*/
|
|
254
|
+
/** Loaded built-in catalog (`de-AT` falls back to `de`), else `undefined` (always for English). */
|
|
260
255
|
function builtinMessages(locale) {
|
|
261
256
|
const language = languageOf(locale);
|
|
262
257
|
return language === void 0 ? void 0 : loadedCatalogs.get(language.locale);
|
|
@@ -266,10 +261,7 @@ function needsMessages(locale) {
|
|
|
266
261
|
const language = languageOf(locale);
|
|
267
262
|
return language?.load !== void 0 && !loadedCatalogs.has(language.locale);
|
|
268
263
|
}
|
|
269
|
-
/**
|
|
270
|
-
* Loads the built-in catalog for `locale` (once; later calls share the result). Await it
|
|
271
|
-
* before mounting to render a non-English editor without first showing English.
|
|
272
|
-
*/
|
|
264
|
+
/** Loads a locale's built-in catalog once; await it before mounting to avoid an English flash. */
|
|
273
265
|
function loadMessages(locale) {
|
|
274
266
|
const language = languageOf(locale);
|
|
275
267
|
if (language?.load === void 0) return Promise.resolve(void 0);
|
|
@@ -291,10 +283,7 @@ function loadMessages(locale) {
|
|
|
291
283
|
}
|
|
292
284
|
const PLURAL = /\{(\w+),\s*plural,\s*((?:[^{}]*\{[^{}]*\})+)\s*\}/g;
|
|
293
285
|
const BRANCH = /(=\d+|zero|one|two|few|many|other)\s*\{([^{}]*)\}/g;
|
|
294
|
-
/**
|
|
295
|
-
* Translator over a message catalog: `{name}` interpolation and
|
|
296
|
-
* `{count, plural, one {…} other {…}}` with `#` for the number (`Intl.PluralRules`).
|
|
297
|
-
*/
|
|
286
|
+
/** Translator with `{name}` interpolation and `{count, plural, …}` (`#` is the number). */
|
|
298
287
|
function createTranslator(messages = {}, locale = "en") {
|
|
299
288
|
const rules = new Intl.PluralRules(locale);
|
|
300
289
|
const numbers = new Intl.NumberFormat(locale);
|
|
@@ -391,10 +380,7 @@ function useResolvedTheme(setting) {
|
|
|
391
380
|
const dark = useSyncExternalStore(subscribeColorScheme, prefersDark, () => false);
|
|
392
381
|
return setting === "system" ? dark ? "dark" : "light" : setting;
|
|
393
382
|
}
|
|
394
|
-
/**
|
|
395
|
-
* Strings, registrations, hidden controls, theme and panel state for UI components.
|
|
396
|
-
* `<DefaultEditor>` renders one; hosts placing components themselves can render their own.
|
|
397
|
-
*/
|
|
383
|
+
/** UI strings, registrations, hidden controls, theme and panel state. */
|
|
398
384
|
function UiProvider({ messages, locale, onLocaleChange, dir = "ltr", registry = fallbackRegistry, hidden = [], theme, onThemeChange, portalContainer = null, initialOpen = [], children }) {
|
|
399
385
|
const [ownTheme, setOwnTheme] = useState(theme ?? "system");
|
|
400
386
|
const themeSetting = onThemeChange === void 0 ? theme ?? ownTheme : theme ?? "system";
|
|
@@ -1082,12 +1068,7 @@ function LinkInput({ id, onDone }) {
|
|
|
1082
1068
|
children: t("link.invalid")
|
|
1083
1069
|
})] });
|
|
1084
1070
|
}
|
|
1085
|
-
/**
|
|
1086
|
-
* Excalidraw-style link editor: a popover above the single selected element. It shows the
|
|
1087
|
-
* element's link (click to open) with edit and remove buttons, or an input while editing
|
|
1088
|
-
* (Mod+K, "Edit link…" in the context menu, the properties action). Enter or clicking away
|
|
1089
|
-
* saves, Escape cancels, an empty link removes it.
|
|
1090
|
-
*/
|
|
1071
|
+
/** Excalidraw-style link editor popover above the single selected element. */
|
|
1091
1072
|
function LinkEditor() {
|
|
1092
1073
|
const editor = useEditor();
|
|
1093
1074
|
const { t, isOpen, setOpen } = useUi();
|
|
@@ -1402,10 +1383,7 @@ function GridControls() {
|
|
|
1402
1383
|
const layerKey = (id) => `layer:${id}`;
|
|
1403
1384
|
const groupKey = (layerId, id) => `group:${layerId}:${id}`;
|
|
1404
1385
|
const elementKey = (id) => `element:${id}`;
|
|
1405
|
-
/**
|
|
1406
|
-
* Flattens layers (top layer first), groups and elements (topmost first) into visible rows.
|
|
1407
|
-
* A group appears in each layer that holds some of its members, at its topmost member.
|
|
1408
|
-
*/
|
|
1386
|
+
/** Visible rows, topmost first; a group shows in each layer at its topmost member. */
|
|
1409
1387
|
function buildLayerRows(source, options) {
|
|
1410
1388
|
const query = options.query?.trim().toLowerCase() ?? "";
|
|
1411
1389
|
const filtering = query !== "" || options.type !== void 0;
|
|
@@ -1488,10 +1466,7 @@ function buildLayerRows(source, options) {
|
|
|
1488
1466
|
for (const node of [...source.layers].reverse().map(buildLayer)) flatten(node, 0);
|
|
1489
1467
|
return rows;
|
|
1490
1468
|
}
|
|
1491
|
-
/**
|
|
1492
|
-
* The indent guide to emphasize for the row at `anchor`: its own children when it is expanded,
|
|
1493
|
-
* otherwise its siblings under the parent row. `end` is exclusive.
|
|
1494
|
-
*/
|
|
1469
|
+
/** Indent guide at `anchor`: its children if expanded, else its siblings (`end` exclusive). */
|
|
1495
1470
|
function activeGuide(rows, anchor) {
|
|
1496
1471
|
const row = rows[anchor];
|
|
1497
1472
|
if (row === void 0) return;
|
|
@@ -1509,10 +1484,7 @@ function activeGuide(rows, anchor) {
|
|
|
1509
1484
|
end
|
|
1510
1485
|
} : void 0;
|
|
1511
1486
|
}
|
|
1512
|
-
/**
|
|
1513
|
-
* Expanded layer rows pinned to the top of the viewport while their contents scroll past,
|
|
1514
|
-
* outermost first. `padding` is the space above the first row.
|
|
1515
|
-
*/
|
|
1487
|
+
/** Expanded layer rows pinned while their contents scroll; `padding` is the space above. */
|
|
1516
1488
|
function stickyRows(rows, scrollTop, rowStride, padding = 0) {
|
|
1517
1489
|
const content = scrollTop - padding;
|
|
1518
1490
|
const result = [];
|
|
@@ -1621,6 +1593,13 @@ function useEventCount(editor, name) {
|
|
|
1621
1593
|
function canLock(editor, row) {
|
|
1622
1594
|
return editor.permissions.can("core.lock", row.kind === "layer" ? { layer: row.record.id } : row.kind === "group" ? { group: row.record.id } : row.record.id);
|
|
1623
1595
|
}
|
|
1596
|
+
function canRename(editor, row) {
|
|
1597
|
+
if (row.kind === "layer") {
|
|
1598
|
+
const target = { layer: row.record.id };
|
|
1599
|
+
return editor.permissions.can("core.manage-layers", target) && editor.permissions.can("core.rename", target);
|
|
1600
|
+
}
|
|
1601
|
+
return row.kind === "group" ? editor.permissions.can("core.group", { group: row.record.id }) : editor.permissions.can("core.edit.content", row.record.id);
|
|
1602
|
+
}
|
|
1624
1603
|
function toggleVisible(editor, row) {
|
|
1625
1604
|
if (row.kind === "layer") editor.layers.setVisible(row.record.id, row.record.hidden);
|
|
1626
1605
|
else if (row.kind === "element") editor.elements.update(row.record.id, { hidden: !row.record.hidden });
|
|
@@ -1721,10 +1700,7 @@ function Thumbnail({ id }) {
|
|
|
1721
1700
|
alt: ""
|
|
1722
1701
|
});
|
|
1723
1702
|
}
|
|
1724
|
-
/**
|
|
1725
|
-
* Layers, groups and elements as a virtualized tree: selection sync, rename, visibility and
|
|
1726
|
-
* lock toggles, search, drag-and-drop reordering and moving between layers.
|
|
1727
|
-
*/
|
|
1703
|
+
/** Virtualized layers tree with rename, toggles, search and drag-and-drop. */
|
|
1728
1704
|
function LayersPanel({ thumbnails = false, onClose }) {
|
|
1729
1705
|
const editor = useEditor();
|
|
1730
1706
|
const { t, openContextMenu, isHidden } = useUi();
|
|
@@ -1820,7 +1796,7 @@ function LayersPanel({ thumbnails = false, onClose }) {
|
|
|
1820
1796
|
if (editing !== void 0) return;
|
|
1821
1797
|
if (event.key === "F2") {
|
|
1822
1798
|
event.preventDefault();
|
|
1823
|
-
setEditing(row.key);
|
|
1799
|
+
if (canRename(editor, row)) setEditing(row.key);
|
|
1824
1800
|
} else if (event.key === "Enter" || event.key === " ") {
|
|
1825
1801
|
event.preventDefault();
|
|
1826
1802
|
select(row, event);
|
|
@@ -1848,12 +1824,7 @@ function LayersPanel({ thumbnails = false, onClose }) {
|
|
|
1848
1824
|
return ratio < .5 ? "above" : "below";
|
|
1849
1825
|
};
|
|
1850
1826
|
const canDrop = (row) => drag.current !== void 0 && (drag.current.kind === "elements" || row.kind === "layer");
|
|
1851
|
-
/**
|
|
1852
|
-
* The drop target under the pointer, from its offset in the list: the gap between two rows
|
|
1853
|
-
* counts as the lower part of the row above, so moving across rows or their children never
|
|
1854
|
-
* clears the indicator. Pinned layer rows take drops themselves, and the empty space below
|
|
1855
|
-
* the rows moves a layer to the bottom of the root.
|
|
1856
|
-
*/
|
|
1827
|
+
/** Drop target at a list offset; gaps count as the row above so the indicator never clears. */
|
|
1857
1828
|
const dropTargetAt = (event) => {
|
|
1858
1829
|
const list = listRef.current;
|
|
1859
1830
|
const content = contentRef.current;
|
|
@@ -1926,13 +1897,15 @@ function LayersPanel({ thumbnails = false, onClose }) {
|
|
|
1926
1897
|
paddingInlineStart: ROW_PADDING + row.depth * INDENT,
|
|
1927
1898
|
["--db-row-indent"]: `${ROW_PADDING + row.depth * INDENT}px`
|
|
1928
1899
|
},
|
|
1929
|
-
title:
|
|
1900
|
+
title: name,
|
|
1930
1901
|
draggable: reorderable && editing !== row.key,
|
|
1931
1902
|
onClick: (event) => {
|
|
1932
1903
|
select(row, event);
|
|
1933
1904
|
if (pinned && listRef.current !== null) listRef.current.scrollTop = TREE_PADDING + (index - row.depth) * ROW_STRIDE;
|
|
1934
1905
|
},
|
|
1935
|
-
onDoubleClick: () =>
|
|
1906
|
+
onDoubleClick: () => {
|
|
1907
|
+
if (canRename(editor, row)) setEditing(row.key);
|
|
1908
|
+
},
|
|
1936
1909
|
onKeyDown: (event) => onRowKeyDown(row, event),
|
|
1937
1910
|
onContextMenu: (event) => {
|
|
1938
1911
|
event.preventDefault();
|
|
@@ -2007,30 +1980,50 @@ function LayersPanel({ thumbnails = false, onClose }) {
|
|
|
2007
1980
|
className: "db-row-actions",
|
|
2008
1981
|
onClick: (event) => event.stopPropagation(),
|
|
2009
1982
|
onDoubleClick: (event) => event.stopPropagation(),
|
|
2010
|
-
children: [
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
1983
|
+
children: [
|
|
1984
|
+
row.kind === "layer" && !isHidden("layers:add") && /* @__PURE__ */ jsx(IconButton, {
|
|
1985
|
+
icon: "add",
|
|
1986
|
+
label: t("layers.addChild"),
|
|
1987
|
+
disabled: !editor.permissions.can("core.manage-layers", { layer: row.record.id }),
|
|
1988
|
+
onClick: () => addLayer(row.record.id),
|
|
1989
|
+
className: "db-row-action",
|
|
1990
|
+
tabIndex: -1,
|
|
1991
|
+
testId: `layer-add-${row.record.id}`
|
|
1992
|
+
}),
|
|
1993
|
+
row.kind !== "group" && /* @__PURE__ */ jsx(IconButton, {
|
|
1994
|
+
icon: isHiddenRow(row) ? "eyeOff" : "eye",
|
|
1995
|
+
label: isHiddenRow(row) ? t("layers.show") : t("layers.hide"),
|
|
1996
|
+
disabled: !lockable,
|
|
1997
|
+
onClick: () => toggleVisible(editor, row),
|
|
1998
|
+
className: "db-row-action",
|
|
1999
|
+
tabIndex: -1,
|
|
2000
|
+
testId: `layer-visibility-${row.record.id}`
|
|
2001
|
+
}),
|
|
2002
|
+
/* @__PURE__ */ jsx(IconButton, {
|
|
2003
|
+
icon: isLocked(row) ? "lock" : "unlock",
|
|
2004
|
+
label: isLocked(row) ? t("layers.unlock") : t("layers.lock"),
|
|
2005
|
+
disabled: !lockable,
|
|
2006
|
+
onClick: () => toggleLocked(editor, row),
|
|
2007
|
+
className: cx("db-row-action", isLocked(row) && "db-on"),
|
|
2008
|
+
tabIndex: -1,
|
|
2009
|
+
testId: `layer-lock-${row.record.id}`
|
|
2010
|
+
})
|
|
2011
|
+
]
|
|
2027
2012
|
})
|
|
2028
2013
|
]
|
|
2029
2014
|
}, row.key);
|
|
2030
2015
|
};
|
|
2031
|
-
const addLayer = () => {
|
|
2032
|
-
const id = editor.layers.create({
|
|
2016
|
+
const addLayer = (parentId) => {
|
|
2017
|
+
const id = editor.layers.create({
|
|
2018
|
+
name: t("layers.newName", { number: editor.layers.list().length + 1 }),
|
|
2019
|
+
...parentId === void 0 ? {} : { parentId }
|
|
2020
|
+
});
|
|
2033
2021
|
editor.layers.setActive(id);
|
|
2022
|
+
if (parentId !== void 0) setCollapsed((current) => {
|
|
2023
|
+
const next = new Set(current);
|
|
2024
|
+
next.delete(layerKey(parentId));
|
|
2025
|
+
return next;
|
|
2026
|
+
});
|
|
2034
2027
|
};
|
|
2035
2028
|
return /* @__PURE__ */ jsxs(Island, {
|
|
2036
2029
|
className: "db-layers",
|
|
@@ -2044,7 +2037,7 @@ function LayersPanel({ thumbnails = false, onClose }) {
|
|
|
2044
2037
|
!isHidden("layers:add") && /* @__PURE__ */ jsx(IconButton, {
|
|
2045
2038
|
icon: "add",
|
|
2046
2039
|
label: t("layers.add"),
|
|
2047
|
-
onClick: addLayer,
|
|
2040
|
+
onClick: () => addLayer(),
|
|
2048
2041
|
testId: "layers-add",
|
|
2049
2042
|
disabled: !editor.permissions.can("core.manage-layers")
|
|
2050
2043
|
}),
|
|
@@ -2141,11 +2134,7 @@ function LayersPanel({ thumbnails = false, onClose }) {
|
|
|
2141
2134
|
});
|
|
2142
2135
|
}
|
|
2143
2136
|
// src/hooks/use-latest.ts
|
|
2144
|
-
/**
|
|
2145
|
-
* A ref that always holds the latest `value`, for callbacks that outlive a render and may also
|
|
2146
|
-
* run during one (where `useEffectEvent` would throw). Updated in an insertion effect, so it is
|
|
2147
|
-
* current before layout effects and event handlers run, and never written during render.
|
|
2148
|
-
*/
|
|
2137
|
+
/** Ref to the latest `value`, safe to read during render (unlike `useEffectEvent`). */
|
|
2149
2138
|
function useLatest(value) {
|
|
2150
2139
|
const ref = useRef(value);
|
|
2151
2140
|
useInsertionEffect(() => {
|
|
@@ -2157,11 +2146,7 @@ function useLatest(value) {
|
|
|
2157
2146
|
function reportError(editor, error, context) {
|
|
2158
2147
|
editor.events.reportError(toError(error), context);
|
|
2159
2148
|
}
|
|
2160
|
-
/**
|
|
2161
|
-
* Registers the UI-level commands the context menu and shortcuts use: copy as PNG
|
|
2162
|
-
* (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+/).
|
|
2163
|
-
* `<DefaultEditor>` renders it; custom layouts can render it too.
|
|
2164
|
-
*/
|
|
2149
|
+
/** Registers UI commands (copy as image, copy link, minimap, canvas settings). */
|
|
2165
2150
|
function CanvasCommands() {
|
|
2166
2151
|
const editor = useEditor();
|
|
2167
2152
|
const [notice, setNotice] = useState(void 0);
|
|
@@ -2270,11 +2255,7 @@ function command(id, commandId, label, order, group, options = {}) {
|
|
|
2270
2255
|
}
|
|
2271
2256
|
const onElement = (context) => context.selection.length > 0;
|
|
2272
2257
|
const onCanvas = (context) => context.selection.length === 0;
|
|
2273
|
-
/**
|
|
2274
|
-
* Built-in context menu entries, in Excalidraw's order; `t` resolves labels at render time.
|
|
2275
|
-
* On an element: clipboard, copy as image, styles, grouping, stacking, flipping, link /
|
|
2276
|
-
* duplicate / lock, delete. On the canvas: paste, copy as image, select all, view toggles.
|
|
2277
|
-
*/
|
|
2258
|
+
/** Built-in context menu entries in Excalidraw's order; `t` resolves labels at render time. */
|
|
2278
2259
|
function builtinContextMenuItems(t, ui) {
|
|
2279
2260
|
const snapping = (context) => context.editor.snapping.settings();
|
|
2280
2261
|
return [
|
|
@@ -2847,10 +2828,7 @@ function isDarkColor(color) {
|
|
|
2847
2828
|
return .2126 * channel(1) + .7152 * channel(3) + .0722 * channel(5) < .35;
|
|
2848
2829
|
}
|
|
2849
2830
|
// src/components/color-picker/color-picker.tsx
|
|
2850
|
-
/**
|
|
2851
|
-
* The browser's EyeDropper (Chromium only): a magnifier that picks a color from anywhere on
|
|
2852
|
-
* screen. `undefined` where unsupported, so the button is hidden there.
|
|
2853
|
-
*/
|
|
2831
|
+
/** Browser EyeDropper (Chromium only); `undefined` hides the button elsewhere. */
|
|
2854
2832
|
function eyeDropperOpener() {
|
|
2855
2833
|
const EyeDropper = typeof window === "undefined" ? void 0 : Reflect.get(window, "EyeDropper");
|
|
2856
2834
|
if (typeof EyeDropper !== "function") return;
|
|
@@ -2866,11 +2844,7 @@ function Swatch({ color }) {
|
|
|
2866
2844
|
style: color === void 0 || color === "transparent" ? void 0 : { background: color }
|
|
2867
2845
|
});
|
|
2868
2846
|
}
|
|
2869
|
-
/**
|
|
2870
|
-
* Excalidraw-style color picker: the color grid (keys q–t, a–g, z–b), the active color's
|
|
2871
|
-
* shades (Shift+1–5; none for transparent, white and black) and a hex code input with a
|
|
2872
|
-
* pipette that copies a color from the screen (EyeDropper, where the browser has it).
|
|
2873
|
-
*/
|
|
2847
|
+
/** Excalidraw-style picker: grid (q–t/a–g/z–b), shades (Shift+1–5), hex input, pipette. */
|
|
2874
2848
|
function ColorPicker({ label, value, kind, onChange }) {
|
|
2875
2849
|
const { t } = useUi();
|
|
2876
2850
|
const active = familyOf(value);
|
|
@@ -3020,10 +2994,7 @@ function ColorPicker({ label, value, kind, onChange }) {
|
|
|
3020
2994
|
]
|
|
3021
2995
|
});
|
|
3022
2996
|
}
|
|
3023
|
-
/**
|
|
3024
|
-
* Quick-pick swatches, then the current color as a button that opens the {@link ColorPicker}
|
|
3025
|
-
* (Excalidraw's stroke and background controls).
|
|
3026
|
-
*/
|
|
2997
|
+
/** Quick-pick swatches plus a button that opens the {@link ColorPicker}. */
|
|
3027
2998
|
function ColorField({ label, value, palette, onChange, kind = "stroke", testId, disabled }) {
|
|
3028
2999
|
const { t } = useUi();
|
|
3029
3000
|
const [open, setOpen] = useState(false);
|
|
@@ -3177,7 +3148,7 @@ function CanvasPropertiesPanel() {
|
|
|
3177
3148
|
}
|
|
3178
3149
|
})]
|
|
3179
3150
|
}),
|
|
3180
|
-
|
|
3151
|
+
/* @__PURE__ */ jsxs("label", {
|
|
3181
3152
|
className: "db-field",
|
|
3182
3153
|
children: [/* @__PURE__ */ jsx("span", { children: t("grid.majorEvery") }), /* @__PURE__ */ jsx("input", {
|
|
3183
3154
|
type: "number",
|
|
@@ -3548,10 +3519,7 @@ function arrowTypeOf(element) {
|
|
|
3548
3519
|
function toolArrowType(props) {
|
|
3549
3520
|
return props.elbowed === true ? "elbow" : props.curved === true ? "curved" : "sharp";
|
|
3550
3521
|
}
|
|
3551
|
-
/**
|
|
3552
|
-
* Edges (sharp or round) and polygon closing for lines, and the arrow type for arrows. Without a
|
|
3553
|
-
* selection it edits the active line or arrow tool's defaults; choices also become new defaults.
|
|
3554
|
-
*/
|
|
3522
|
+
/** Edge, polygon and arrow-type controls; without a selection they edit the tool defaults. */
|
|
3555
3523
|
function LinearProperties() {
|
|
3556
3524
|
const editor = useEditor();
|
|
3557
3525
|
const { t } = useUi();
|
|
@@ -3689,10 +3657,7 @@ function previewFont(editor, id) {
|
|
|
3689
3657
|
style: "normal"
|
|
3690
3658
|
});
|
|
3691
3659
|
}
|
|
3692
|
-
/**
|
|
3693
|
-
* Searchable list of every registered font, with the fonts the document uses first. Each name
|
|
3694
|
-
* is drawn in its own font. Arrow keys move, Enter picks.
|
|
3695
|
-
*/
|
|
3660
|
+
/** Searchable font list, document fonts first, each name drawn in its own font. */
|
|
3696
3661
|
function FontPicker({ value, onChange }) {
|
|
3697
3662
|
const editor = useEditor();
|
|
3698
3663
|
const { t } = useUi();
|
|
@@ -3822,10 +3787,7 @@ function FontPicker({ value, onChange }) {
|
|
|
3822
3787
|
})]
|
|
3823
3788
|
});
|
|
3824
3789
|
}
|
|
3825
|
-
/**
|
|
3826
|
-
* Quick picks for the hand-drawn, normal and code fonts, then a button that opens the
|
|
3827
|
-
* {@link FontPicker}. The button is highlighted while any other font is set.
|
|
3828
|
-
*/
|
|
3790
|
+
/** Hand/normal/code quick picks plus a {@link FontPicker} button, lit for any other font. */
|
|
3829
3791
|
function FontFamilyField({ value, onChange, testId }) {
|
|
3830
3792
|
const editor = useEditor();
|
|
3831
3793
|
const { t } = useUi();
|
|
@@ -3934,6 +3896,20 @@ const TEXT_KEYS = /* @__PURE__ */ new Set([
|
|
|
3934
3896
|
"textColor",
|
|
3935
3897
|
"lineHeight"
|
|
3936
3898
|
]);
|
|
3899
|
+
/** Style keys with their own section when there is no selection (text color only for the text tool). */
|
|
3900
|
+
const TOOL_PANEL_KEYS = [
|
|
3901
|
+
"strokeColor",
|
|
3902
|
+
"fillColor",
|
|
3903
|
+
"fillStyle",
|
|
3904
|
+
"strokeWidth",
|
|
3905
|
+
"strokeStyle",
|
|
3906
|
+
"roughness",
|
|
3907
|
+
"cornerRadius",
|
|
3908
|
+
"startArrowhead",
|
|
3909
|
+
"fontFamily",
|
|
3910
|
+
"fontSize",
|
|
3911
|
+
"textAlign"
|
|
3912
|
+
];
|
|
3937
3913
|
function asString(value) {
|
|
3938
3914
|
return typeof value === "string" ? value : void 0;
|
|
3939
3915
|
}
|
|
@@ -4137,17 +4113,14 @@ function CustomEditors({ elements }) {
|
|
|
4137
4113
|
}, type);
|
|
4138
4114
|
});
|
|
4139
4115
|
}
|
|
4140
|
-
/**
|
|
4141
|
-
* Styles of the selection (or of the active drawing tool's defaults), element actions and
|
|
4142
|
-
* registered custom property editors. Mixed values show no selected option.
|
|
4143
|
-
*/
|
|
4116
|
+
/** Selection styles (or tool defaults), actions and custom editors; mixed values show none. */
|
|
4144
4117
|
function PropertiesPanel() {
|
|
4145
4118
|
const editor = useEditor();
|
|
4146
4119
|
const { t } = useUi();
|
|
4147
4120
|
const selected = useSelectedElements();
|
|
4148
4121
|
const target = useStyleTarget();
|
|
4149
4122
|
const tool = useActiveTool();
|
|
4150
|
-
if (
|
|
4123
|
+
if (selected.length === 0 && !(tool === TEXT_TOOL && target?.keys.has("textColor") === true) && !TOOL_PANEL_KEYS.some((key) => target?.keys.has(key) === true)) return null;
|
|
4151
4124
|
const hasText = selected.length === 0 || selected.some((element) => element.type === "core.text" || (editor.text.layoutOf(element)?.text ?? "") !== "");
|
|
4152
4125
|
const has = (key) => target?.keys.has(key) === true && (!TEXT_KEYS.has(key) || hasText);
|
|
4153
4126
|
const value = (key) => target?.values[key];
|
|
@@ -4440,10 +4413,7 @@ function install(registry, plugin) {
|
|
|
4440
4413
|
for (const [id, component] of Object.entries(facet?.icons ?? {})) undo.push(registry.icons.register(id, component));
|
|
4441
4414
|
return () => undo.forEach((step) => step());
|
|
4442
4415
|
}
|
|
4443
|
-
/**
|
|
4444
|
-
* Installs the `ui` facets of the editor's plugins into the UI registry and follows later
|
|
4445
|
-
* installs and uninstalls. `<DefaultEditor>` renders it; custom layouts can render it too.
|
|
4446
|
-
*/
|
|
4416
|
+
/** Installs the editor plugins' `ui` facets into the registry and follows (un)installs. */
|
|
4447
4417
|
function UiPlugins() {
|
|
4448
4418
|
const editor = useEditor();
|
|
4449
4419
|
const { registry } = useUi();
|
|
@@ -4474,10 +4444,10 @@ const TOOL_ORDER = {
|
|
|
4474
4444
|
"core.line": 410,
|
|
4475
4445
|
"core.freedraw": 500,
|
|
4476
4446
|
"core.text": 510,
|
|
4477
|
-
"core.image": 520,
|
|
4478
4447
|
"core.eraser": 600,
|
|
4479
|
-
"core.
|
|
4480
|
-
"core.
|
|
4448
|
+
"core.image": 900,
|
|
4449
|
+
"core.frame": 910,
|
|
4450
|
+
"core.laser": 920
|
|
4481
4451
|
};
|
|
4482
4452
|
const GROUP_BREAKS = /* @__PURE__ */ new Set([
|
|
4483
4453
|
300,
|
|
@@ -4485,12 +4455,8 @@ const GROUP_BREAKS = /* @__PURE__ */ new Set([
|
|
|
4485
4455
|
500,
|
|
4486
4456
|
600
|
|
4487
4457
|
]);
|
|
4488
|
-
/** Tools
|
|
4489
|
-
const
|
|
4490
|
-
"core.image",
|
|
4491
|
-
"core.frame",
|
|
4492
|
-
"core.laser"
|
|
4493
|
-
]);
|
|
4458
|
+
/** Tools ordered at or after this go into the toolbar's "more tools" menu (like Excalidraw). */
|
|
4459
|
+
const OVERFLOW_ORDER = 900;
|
|
4494
4460
|
/** Toolbar button with a menu of the less used tools; pressed while one of them is active. */
|
|
4495
4461
|
function ToolOverflow({ tools }) {
|
|
4496
4462
|
const editor = useEditor();
|
|
@@ -4566,19 +4532,20 @@ function ToolLockButton() {
|
|
|
4566
4532
|
testId: "tool-lock"
|
|
4567
4533
|
});
|
|
4568
4534
|
}
|
|
4569
|
-
/**
|
|
4570
|
-
* Available tools in a fixed group order (unknown custom tools after the built-ins), plus
|
|
4571
|
-
* registered toolbar items placed by `order`. Arrow keys move between buttons.
|
|
4572
|
-
*/
|
|
4535
|
+
/** Tools in fixed group order plus custom items by `order`; arrow keys move between them. */
|
|
4573
4536
|
function Toolbar({ start, end }) {
|
|
4574
4537
|
const tools = useTools();
|
|
4575
4538
|
const { t, registry, isHidden } = useUi();
|
|
4576
|
-
const
|
|
4577
|
-
const visible = available.filter((tool) => !OVERFLOW_TOOLS.has(tool.id));
|
|
4578
|
-
const overflow = available.filter((tool) => OVERFLOW_TOOLS.has(tool.id));
|
|
4579
|
-
const entries = byOrder([...visible.map((tool, index) => ({
|
|
4539
|
+
const ordered = byOrder(tools.filter((tool) => tool.available && !isHidden(`tool:${tool.id}`)).map((tool, index) => ({
|
|
4580
4540
|
id: tool.id,
|
|
4581
4541
|
order: TOOL_ORDER[tool.id] ?? 800 + index,
|
|
4542
|
+
tool
|
|
4543
|
+
})));
|
|
4544
|
+
const visible = ordered.filter((entry) => entry.order < OVERFLOW_ORDER);
|
|
4545
|
+
const overflow = ordered.filter((entry) => entry.order >= OVERFLOW_ORDER).map((entry) => entry.tool);
|
|
4546
|
+
const entries = byOrder([...visible.map(({ id, order, tool }) => ({
|
|
4547
|
+
id,
|
|
4548
|
+
order,
|
|
4582
4549
|
render: () => /* @__PURE__ */ jsx(ToolButton, {
|
|
4583
4550
|
id: tool.id,
|
|
4584
4551
|
...tool.label === void 0 ? {} : { fallbackLabel: tool.label },
|
|
@@ -4613,18 +4580,16 @@ function Toolbar({ start, end }) {
|
|
|
4613
4580
|
});
|
|
4614
4581
|
}
|
|
4615
4582
|
// src/app/default-editor.tsx
|
|
4616
|
-
const THEME_BACKGROUND = {
|
|
4617
|
-
light: "#ffffff",
|
|
4618
|
-
dark: "#121212"
|
|
4619
|
-
};
|
|
4620
4583
|
function Layout({ components = {}, slots = {}, canvas, minimapRenderers, fileName, onMount }) {
|
|
4621
|
-
const editor = useEditor();
|
|
4622
4584
|
const { t, isHidden, isOpen, setOpen, theme } = useUi();
|
|
4623
4585
|
const presentation = usePresentation();
|
|
4624
4586
|
const mode = useMode();
|
|
4625
4587
|
const selection = useSelection();
|
|
4626
4588
|
const tool = useActiveTool();
|
|
4627
|
-
const drawingTool = useEditorValue((editor) =>
|
|
4589
|
+
const drawingTool = useEditorValue((editor) => {
|
|
4590
|
+
const active = editor.tools.active();
|
|
4591
|
+
return editor.elements.definitionOf(active) !== void 0 && editor.styles.supportedKeys(active).length > 0;
|
|
4592
|
+
}, { events: ["tool.change"] });
|
|
4628
4593
|
const onContextMenu = useContextMenuForCanvas();
|
|
4629
4594
|
const zen = presentation.zen;
|
|
4630
4595
|
const viewing = mode === "view";
|
|
@@ -4644,7 +4609,7 @@ function Layout({ components = {}, slots = {}, canvas, minimapRenderers, fileNam
|
|
|
4644
4609
|
const canvasOptions = useMemo(() => ({
|
|
4645
4610
|
...canvas,
|
|
4646
4611
|
linkBadges: canvas?.linkBadges ?? (linkEditorShown ? "unselected" : true),
|
|
4647
|
-
|
|
4612
|
+
theme: canvas?.theme ?? theme,
|
|
4648
4613
|
...contextMenuEnabled ? { onContextMenu } : {}
|
|
4649
4614
|
}), [
|
|
4650
4615
|
canvas,
|
|
@@ -4709,15 +4674,9 @@ function Layout({ components = {}, slots = {}, canvas, minimapRenderers, fileNam
|
|
|
4709
4674
|
slots.bottomLeft
|
|
4710
4675
|
]
|
|
4711
4676
|
}),
|
|
4712
|
-
/* @__PURE__ */
|
|
4677
|
+
/* @__PURE__ */ jsx("div", {
|
|
4713
4678
|
className: "db-bottom-center",
|
|
4714
|
-
children:
|
|
4715
|
-
type: "button",
|
|
4716
|
-
className: "db-pill",
|
|
4717
|
-
"data-testid": "exit-zen",
|
|
4718
|
-
onClick: () => editor.modes.setPresentation({ zen: false }),
|
|
4719
|
-
children: t("zen.exit")
|
|
4720
|
-
})]
|
|
4679
|
+
children: show("scrollToContent") && /* @__PURE__ */ jsx(ScrollToContent, {})
|
|
4721
4680
|
}),
|
|
4722
4681
|
/* @__PURE__ */ jsxs("div", {
|
|
4723
4682
|
className: "db-bottom-right",
|
|
@@ -4745,10 +4704,7 @@ function Layout({ components = {}, slots = {}, canvas, minimapRenderers, fileNam
|
|
|
4745
4704
|
]
|
|
4746
4705
|
});
|
|
4747
4706
|
}
|
|
4748
|
-
/**
|
|
4749
|
-
* Complete editor: canvas plus the default controls inside the given container. Renders its own
|
|
4750
|
-
* `EditorProvider` and `UiProvider`; every control can be hidden, replaced or extended.
|
|
4751
|
-
*/
|
|
4707
|
+
/** Complete editor: canvas plus default controls, each of which can be hidden or replaced. */
|
|
4752
4708
|
function DefaultEditor({ editor, theme, onThemeChange, messages, locale, onLocaleChange, dir = "ltr", hidden, components, registry, slots, canvas, minimapRenderers, initialOpen, fileName, className, onMount }) {
|
|
4753
4709
|
const [root, setRoot] = useState(null);
|
|
4754
4710
|
const [ownTheme, setOwnTheme] = useState(theme ?? "system");
|
|
@@ -4783,10 +4739,7 @@ function DefaultEditor({ editor, theme, onThemeChange, messages, locale, onLocal
|
|
|
4783
4739
|
})
|
|
4784
4740
|
});
|
|
4785
4741
|
}
|
|
4786
|
-
/**
|
|
4787
|
-
* Scoped root element for UI components: carries the theme, direction and the `.db-editor`
|
|
4788
|
-
* class all styles are scoped to. Opens the shortcut reference on `?`.
|
|
4789
|
-
*/
|
|
4742
|
+
/** Scoped root for UI components: theme, direction and `.db-editor`; `?` opens shortcuts. */
|
|
4790
4743
|
function EditorRoot({ ref, className, dir, children }) {
|
|
4791
4744
|
const { theme, setOpen } = useUi();
|
|
4792
4745
|
const [element, setElement] = useState(null);
|
package/dist/locales/de.d.mts
CHANGED
package/dist/locales/de.mjs
CHANGED
|
@@ -179,6 +179,7 @@ const de = {
|
|
|
179
179
|
"layers.toggle": "Ebenen",
|
|
180
180
|
"layers.search": "Suchen",
|
|
181
181
|
"layers.add": "Ebene hinzufügen",
|
|
182
|
+
"layers.addChild": "Ebene darin hinzufügen",
|
|
182
183
|
"layers.newName": "Ebene {number}",
|
|
183
184
|
"layers.show": "Einblenden",
|
|
184
185
|
"layers.hide": "Ausblenden",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drawback/ui",
|
|
3
|
-
"version": "0.2.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Default React editor UI for the API-first interactive canvas engine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"canvas",
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"api-report": "api-extractor run --config api-extractor.json --local"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@drawback/canvas": "^0.2.0
|
|
57
|
-
"@drawback/core": "^0.2.0
|
|
58
|
-
"@drawback/react": "^0.2.0
|
|
56
|
+
"@drawback/canvas": "^0.2.0",
|
|
57
|
+
"@drawback/core": "^0.2.0",
|
|
58
|
+
"@drawback/react": "^0.2.0",
|
|
59
59
|
"lucide-react": "^1.84.0"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|