@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.
Files changed (38) hide show
  1. package/README.md +22 -2
  2. package/dist/i18n-BZnCrD-C.d.mts +265 -0
  3. package/dist/index.d.mts +588 -0
  4. package/dist/index.mjs +4821 -0
  5. package/dist/locales/de.d.mts +3 -0
  6. package/dist/locales/de.mjs +231 -0
  7. package/package.json +69 -4
  8. package/src/app/default-editor.tsx +371 -0
  9. package/src/components/color-picker/color-picker.tsx +341 -0
  10. package/src/components/color-picker/colors.ts +135 -0
  11. package/src/components/font-picker/font-picker.tsx +298 -0
  12. package/src/components/icons.tsx +222 -0
  13. package/src/components/primitives.tsx +565 -0
  14. package/src/components/style-icons.tsx +172 -0
  15. package/src/features/canvas-commands/canvas-commands.tsx +173 -0
  16. package/src/features/context-menu/context-menu.tsx +354 -0
  17. package/src/features/controls/controls.tsx +281 -0
  18. package/src/features/export/export-dialog.tsx +164 -0
  19. package/src/features/layers/layers-tree.ts +335 -0
  20. package/src/features/layers/layers.tsx +858 -0
  21. package/src/features/links/links.tsx +268 -0
  22. package/src/features/main-menu/canvas-properties.tsx +121 -0
  23. package/src/features/main-menu/main-menu.tsx +215 -0
  24. package/src/features/minimap/minimap.tsx +69 -0
  25. package/src/features/properties/linear-properties.tsx +169 -0
  26. package/src/features/properties/properties.tsx +573 -0
  27. package/src/features/shortcuts/shortcuts-dialog.tsx +120 -0
  28. package/src/features/toolbar/toolbar.tsx +216 -0
  29. package/src/hooks/use-latest.ts +16 -0
  30. package/src/index.ts +138 -0
  31. package/src/lib/commands.ts +14 -0
  32. package/src/lib/download.ts +8 -0
  33. package/src/lib/i18n.ts +350 -0
  34. package/src/lib/locales/de.ts +231 -0
  35. package/src/lib/plugins.tsx +92 -0
  36. package/src/lib/registry.ts +140 -0
  37. package/src/stores/ui-context.tsx +253 -0
  38. package/src/styles.css +1366 -0
@@ -0,0 +1,169 @@
1
+ import {
2
+ ARROW_TYPE,
3
+ LINE_TYPE,
4
+ isArrowElbowed,
5
+ isLinearClosed,
6
+ isLinearCurved,
7
+ linearWorldPoints,
8
+ type AnyEditor,
9
+ type ArrowType,
10
+ type ElementRecord,
11
+ type JsonObject,
12
+ } from '@drawback/core';
13
+ import { useActiveTool, useEditor, useSelectedElements } from '@drawback/react';
14
+ import { useState, type ReactNode } from 'react';
15
+ import { useUi } from '../../stores/ui-context.js';
16
+ import { Choice, Section } from '../../components/primitives.js';
17
+
18
+ type Edge = 'sharp' | 'round';
19
+ type Outline = 'open' | 'closed';
20
+
21
+ function uniform<Value>(values: readonly Value[]): Value | undefined {
22
+ const [first] = values;
23
+ return values.every((value) => value === first) ? first : undefined;
24
+ }
25
+
26
+ function toolProps(editor: AnyEditor, toolId: string): JsonObject {
27
+ const props = editor.tools.getDefaults(toolId).props;
28
+ return props !== null && typeof props === 'object' && !Array.isArray(props)
29
+ ? (props as JsonObject)
30
+ : {};
31
+ }
32
+
33
+ function setToolProps(editor: AnyEditor, toolId: string, patch: JsonObject): void {
34
+ if (!editor.tools.has(toolId)) {
35
+ return;
36
+ }
37
+
38
+ const defaults = editor.tools.getDefaults(toolId);
39
+ editor.tools.setDefaults(toolId, {
40
+ ...defaults,
41
+ props: { ...toolProps(editor, toolId), ...patch },
42
+ });
43
+ }
44
+
45
+ function arrowTypeOf(element: ElementRecord): ArrowType {
46
+ return isArrowElbowed(element) ? 'elbow' : isLinearCurved(element) ? 'curved' : 'sharp';
47
+ }
48
+
49
+ function toolArrowType(props: JsonObject): ArrowType {
50
+ return props.elbowed === true ? 'elbow' : props.curved === true ? 'curved' : 'sharp';
51
+ }
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
+ */
57
+ export function LinearProperties(): ReactNode {
58
+ const editor = useEditor();
59
+ const { t } = useUi();
60
+ const selected = useSelectedElements();
61
+ const tool = useActiveTool();
62
+ const [, refresh] = useState(0);
63
+ const editable = selected.filter(
64
+ (element) =>
65
+ !editor.elements.isLocked(element.id) && editor.permissions.can('core.resize', element.id),
66
+ );
67
+ const lines = editable.filter((element) => element.type === LINE_TYPE);
68
+ const arrows = editable.filter((element) => element.type === ARROW_TYPE);
69
+ const toolMode = selected.length === 0;
70
+ const showLines = toolMode ? tool === LINE_TYPE : lines.length > 0;
71
+ const showArrows = toolMode ? tool === ARROW_TYPE : arrows.length > 0;
72
+ const polygonCandidates = lines.filter((element) => linearWorldPoints(element).length >= 3);
73
+ const showPolygon =
74
+ !toolMode && polygonCandidates.length > 0 && polygonCandidates.length === lines.length;
75
+
76
+ if (!showLines && !showArrows) {
77
+ return null;
78
+ }
79
+
80
+ const edge: Edge | undefined = toolMode
81
+ ? toolProps(editor, LINE_TYPE).curved === false
82
+ ? 'sharp'
83
+ : 'round'
84
+ : uniform(lines.map((element) => (isLinearCurved(element) ? 'round' : 'sharp')));
85
+ const arrowType: ArrowType | undefined = toolMode
86
+ ? toolArrowType(toolProps(editor, ARROW_TYPE))
87
+ : uniform(arrows.map(arrowTypeOf));
88
+ const outline: Outline | undefined = uniform(
89
+ lines.map((element) => (isLinearClosed(element) ? 'closed' : 'open')),
90
+ );
91
+
92
+ return (
93
+ <>
94
+ {showLines && (
95
+ <Section title={t('properties.cornerRadius')}>
96
+ <Choice
97
+ label={t('properties.cornerRadius')}
98
+ value={edge}
99
+ options={[
100
+ { value: 'sharp', label: t('value.sharp'), icon: 'edgeSharp' },
101
+ { value: 'round', label: t('value.round'), icon: 'edgeRound' },
102
+ ]}
103
+ onChange={(next) => {
104
+ const curved = next === 'round';
105
+
106
+ if (lines.length > 0) {
107
+ editor.linear.setCurved(
108
+ lines.map((element) => element.id),
109
+ curved,
110
+ );
111
+ }
112
+
113
+ setToolProps(editor, LINE_TYPE, { curved });
114
+ refresh((count) => count + 1);
115
+ }}
116
+ testId="line-edges"
117
+ />
118
+ </Section>
119
+ )}
120
+ {showPolygon && (
121
+ <Section title={t('properties.polygon')}>
122
+ <Choice
123
+ label={t('properties.polygon')}
124
+ value={outline}
125
+ options={[
126
+ { value: 'open', label: t('value.open'), icon: 'polyline' },
127
+ { value: 'closed', label: t('value.closed'), icon: 'polygon' },
128
+ ]}
129
+ onChange={(next) =>
130
+ editor.linear.setClosed(
131
+ lines.map((element) => element.id),
132
+ next === 'closed',
133
+ )
134
+ }
135
+ testId="line-polygon"
136
+ />
137
+ </Section>
138
+ )}
139
+ {showArrows && (
140
+ <Section title={t('properties.arrowType')}>
141
+ <Choice
142
+ label={t('properties.arrowType')}
143
+ value={arrowType}
144
+ options={[
145
+ { value: 'sharp', label: t('value.sharp'), icon: 'arrowSharp' },
146
+ { value: 'curved', label: t('value.curved'), icon: 'arrowCurved' },
147
+ { value: 'elbow', label: t('value.elbow'), icon: 'arrowElbow' },
148
+ ]}
149
+ onChange={(next) => {
150
+ if (arrows.length > 0) {
151
+ editor.linear.setArrowType(
152
+ arrows.map((element) => element.id),
153
+ next,
154
+ );
155
+ }
156
+
157
+ setToolProps(editor, ARROW_TYPE, {
158
+ curved: next === 'curved',
159
+ elbowed: next === 'elbow',
160
+ });
161
+ refresh((count) => count + 1);
162
+ }}
163
+ testId="arrow-type"
164
+ />
165
+ </Section>
166
+ )}
167
+ </>
168
+ );
169
+ }