@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.
@@ -22,16 +22,16 @@ const TOOL_ORDER: Readonly<Record<string, number>> = {
22
22
  'core.line': 410,
23
23
  'core.freedraw': 500,
24
24
  'core.text': 510,
25
- 'core.image': 520,
26
25
  'core.eraser': 600,
27
- 'core.frame': 690,
28
- 'core.laser': 700,
26
+ 'core.image': 900,
27
+ 'core.frame': 910,
28
+ 'core.laser': 920,
29
29
  };
30
30
 
31
31
  const GROUP_BREAKS = new Set([300, 400, 500, 600]);
32
32
 
33
- /** Tools listed in the toolbar's "more tools" menu instead of as buttons (like Excalidraw). */
34
- const OVERFLOW_TOOLS: ReadonlySet<string> = new Set(['core.image', 'core.frame', 'core.laser']);
33
+ /** Tools ordered at or after this go into the toolbar's "more tools" menu (like Excalidraw). */
34
+ const OVERFLOW_ORDER = 900;
35
35
 
36
36
  type ToolInfo = ReturnType<typeof useTools>[number];
37
37
 
@@ -150,20 +150,26 @@ export interface ToolbarProps {
150
150
  readonly end?: ReactNode;
151
151
  }
152
152
 
153
- /**
154
- * Available tools in a fixed group order (unknown custom tools after the built-ins), plus
155
- * registered toolbar items placed by `order`. Arrow keys move between buttons.
156
- */
153
+ /** Tools in fixed group order plus custom items by `order`; arrow keys move between them. */
157
154
  export function Toolbar({ start, end }: ToolbarProps): ReactNode {
158
155
  const tools = useTools();
159
156
  const { t, registry, isHidden } = useUi();
160
157
  const available = tools.filter((tool) => tool.available && !isHidden(`tool:${tool.id}`));
161
- const visible = available.filter((tool) => !OVERFLOW_TOOLS.has(tool.id));
162
- const overflow = available.filter((tool) => OVERFLOW_TOOLS.has(tool.id));
163
- const entries = byOrder([
164
- ...visible.map((tool, index) => ({
158
+ const ordered = byOrder(
159
+ available.map((tool, index) => ({
165
160
  id: tool.id,
166
161
  order: TOOL_ORDER[tool.id] ?? 800 + index,
162
+ tool,
163
+ })),
164
+ );
165
+ const visible = ordered.filter((entry) => entry.order < OVERFLOW_ORDER);
166
+ const overflow = ordered
167
+ .filter((entry) => entry.order >= OVERFLOW_ORDER)
168
+ .map((entry) => entry.tool);
169
+ const entries = byOrder([
170
+ ...visible.map(({ id, order, tool }) => ({
171
+ id,
172
+ order,
167
173
  render: () => (
168
174
  <ToolButton
169
175
  id={tool.id}
@@ -1,10 +1,6 @@
1
1
  import { useInsertionEffect, useRef, type RefObject } from 'react';
2
2
 
3
- /**
4
- * A ref that always holds the latest `value`, for callbacks that outlive a render and may also
5
- * run during one (where `useEffectEvent` would throw). Updated in an insertion effect, so it is
6
- * current before layout effects and event handlers run, and never written during render.
7
- */
3
+ /** Ref to the latest `value`, safe to read during render (unlike `useEffectEvent`). */
8
4
  export function useLatest<Value>(value: Value): RefObject<Value> {
9
5
  const ref = useRef(value);
10
6
 
package/src/lib/i18n.ts CHANGED
@@ -178,6 +178,7 @@ export const en = {
178
178
  'layers.toggle': 'Layers',
179
179
  'layers.search': 'Search',
180
180
  'layers.add': 'Add layer',
181
+ 'layers.addChild': 'Add layer inside',
181
182
  'layers.newName': 'Layer {number}',
182
183
  'layers.show': 'Show',
183
184
  'layers.hide': 'Hide',
@@ -238,10 +239,7 @@ export interface LanguageInfo {
238
239
  readonly load?: () => Promise<Messages>;
239
240
  }
240
241
 
241
- /**
242
- * Built-in languages, offered in the main menu's language picker under their own names.
243
- * Catalogs other than English are separate chunks, loaded when a locale first needs them.
244
- */
242
+ /** Built-in languages; non-English catalogs are separate chunks loaded on first use. */
245
243
  export const LANGUAGES: readonly LanguageInfo[] = [
246
244
  { locale: 'en', name: 'English' },
247
245
  {
@@ -259,10 +257,7 @@ function languageOf(locale: string): LanguageInfo | undefined {
259
257
  return LANGUAGES.find((entry) => entry.locale === base);
260
258
  }
261
259
 
262
- /**
263
- * Built-in catalog for a locale (`de-AT` falls back to `de`) once it has loaded, else
264
- * `undefined` (always for English). See {@link loadMessages}.
265
- */
260
+ /** Loaded built-in catalog (`de-AT` falls back to `de`), else `undefined` (always for English). */
266
261
  export function builtinMessages(locale: string): Messages | undefined {
267
262
  const language = languageOf(locale);
268
263
  return language === undefined ? undefined : loadedCatalogs.get(language.locale);
@@ -274,10 +269,7 @@ export function needsMessages(locale: string): boolean {
274
269
  return language?.load !== undefined && !loadedCatalogs.has(language.locale);
275
270
  }
276
271
 
277
- /**
278
- * Loads the built-in catalog for `locale` (once; later calls share the result). Await it
279
- * before mounting to render a non-English editor without first showing English.
280
- */
272
+ /** Loads a locale's built-in catalog once; await it before mounting to avoid an English flash. */
281
273
  export function loadMessages(locale: string): Promise<Messages | undefined> {
282
274
  const language = languageOf(locale);
283
275
 
@@ -319,10 +311,7 @@ export type Translate = (key: MessageKey | (string & {}), values?: TranslateValu
319
311
  const PLURAL = /\{(\w+),\s*plural,\s*((?:[^{}]*\{[^{}]*\})+)\s*\}/g;
320
312
  const BRANCH = /(=\d+|zero|one|two|few|many|other)\s*\{([^{}]*)\}/g;
321
313
 
322
- /**
323
- * Translator over a message catalog: `{name}` interpolation and
324
- * `{count, plural, one {…} other {…}}` with `#` for the number (`Intl.PluralRules`).
325
- */
314
+ /** Translator with `{name}` interpolation and `{count, plural, …}` (`#` is the number). */
326
315
  export function createTranslator(messages: Messages = {}, locale = 'en'): Translate {
327
316
  const rules = new Intl.PluralRules(locale);
328
317
  const numbers = new Intl.NumberFormat(locale);
@@ -180,6 +180,7 @@ export const de: { readonly [Key in MessageKey]: string } = {
180
180
  'layers.toggle': 'Ebenen',
181
181
  'layers.search': 'Suchen',
182
182
  'layers.add': 'Ebene hinzufügen',
183
+ 'layers.addChild': 'Ebene darin hinzufügen',
183
184
  'layers.newName': 'Ebene {number}',
184
185
  'layers.show': 'Einblenden',
185
186
  'layers.hide': 'Ausblenden',
@@ -50,15 +50,11 @@ function install(registry: UiRegistry, plugin: EditorPlugin): () => void {
50
50
  return () => undo.forEach((step) => step());
51
51
  }
52
52
 
53
- /**
54
- * Installs the `ui` facets of the editor's plugins into the UI registry and follows later
55
- * installs and uninstalls. `<DefaultEditor>` renders it; custom layouts can render it too.
56
- */
53
+ /** Installs the editor plugins' `ui` facets into the registry and follows (un)installs. */
57
54
  export function UiPlugins(): null {
58
55
  const editor = useEditor();
59
56
  const { registry } = useUi();
60
57
 
61
- // Syncs the registry with an external system (the editor's plugin list).
62
58
  useEffect(() => {
63
59
  const installed = new Map<string, () => void>();
64
60
 
@@ -93,10 +93,7 @@ export function useResolvedTheme(setting: ThemeSetting): ResolvedTheme {
93
93
  return setting === 'system' ? (dark ? 'dark' : 'light') : setting;
94
94
  }
95
95
 
96
- /**
97
- * Strings, registrations, hidden controls, theme and panel state for UI components.
98
- * `<DefaultEditor>` renders one; hosts placing components themselves can render their own.
99
- */
96
+ /** UI strings, registrations, hidden controls, theme and panel state. */
100
97
  export function UiProvider({
101
98
  messages,
102
99
  locale,
@@ -119,8 +116,7 @@ export function UiProvider({
119
116
  const registryVersion = registry.version();
120
117
  const [ownLocale, setOwnLocale] = useState(locale ?? 'en');
121
118
  const currentLocale = onLocaleChange === undefined ? (locale ?? ownLocale) : (locale ?? 'en');
122
- // The last catalog that was ready. While a newly picked language loads, it stays on screen,
123
- // so the UI never flashes English; loaded catalogs are cached and apply immediately.
119
+ // Keep the last ready catalog while a new language loads, so English never flashes.
124
120
  const [shown, setShown] = useState<{ readonly locale: string; readonly messages?: Messages }>({
125
121
  locale: 'en',
126
122
  });
package/src/styles.css CHANGED
@@ -632,6 +632,19 @@
632
632
  color: rgb(255 255 255 / 75%);
633
633
  }
634
634
 
635
+ /* Swatches show colors as the dark canvas does (same filter as the scene). */
636
+ .db-editor[data-theme='dark'] .db-swatch:not(.db-swatch-mixed) {
637
+ filter: invert(93%) hue-rotate(180deg);
638
+ }
639
+
640
+ .db-editor[data-theme='dark'] .db-color-cell .db-color-key {
641
+ color: rgb(255 255 255 / 75%);
642
+ }
643
+
644
+ .db-editor[data-theme='dark'] .db-color-cell.db-on-dark .db-color-key {
645
+ color: rgb(0 0 0 / 45%);
646
+ }
647
+
635
648
  .db-editor .db-color-no-shades {
636
649
  margin: 0 0 6px;
637
650
  padding: 8px 0;