js-draw 0.16.0 → 0.17.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/CHANGELOG.md +15 -0
- package/dist/bundle.js +1 -1
- package/dist/src/Editor.js +2 -1
- package/dist/src/EditorImage.js +12 -5
- package/dist/src/SVGLoader.js +6 -0
- package/dist/src/UndoRedoHistory.d.ts +2 -3
- package/dist/src/UndoRedoHistory.js +37 -20
- package/dist/src/components/RestylableComponent.js +2 -2
- package/dist/src/components/localization.d.ts +1 -1
- package/dist/src/components/localization.js +1 -1
- package/dist/src/lib.d.ts +1 -0
- package/dist/src/lib.js +1 -0
- package/dist/src/toolbar/HTMLToolbar.d.ts +1 -0
- package/dist/src/toolbar/HTMLToolbar.js +4 -1
- package/dist/src/toolbar/widgets/OverflowWidget.js +6 -0
- package/dist/src/tools/SelectionTool/SelectionTool.js +1 -1
- package/dist/src/types.d.ts +7 -0
- package/dist/src/types.js +7 -0
- package/package.json +1 -1
- package/src/Editor.css +4 -0
- package/src/Editor.ts +3 -1
- package/src/EditorImage.ts +11 -6
- package/src/SVGLoader.test.ts +57 -0
- package/src/SVGLoader.ts +7 -0
- package/src/UndoRedoHistory.ts +28 -23
- package/src/components/RestylableComponent.ts +2 -2
- package/src/components/localization.ts +2 -2
- package/src/lib.ts +1 -0
- package/src/toolbar/HTMLToolbar.ts +6 -1
- package/src/toolbar/toolbar.css +7 -1
- package/src/toolbar/widgets/OverflowWidget.css +20 -2
- package/src/toolbar/widgets/OverflowWidget.ts +9 -0
- package/src/tools/SelectionTool/SelectionTool.ts +1 -1
- package/src/types.ts +11 -1
@@ -7,16 +7,16 @@ export interface ImageComponentLocalization {
|
|
7
7
|
emptyBackground: string;
|
8
8
|
filledBackgroundWithColor: (color: string)=> string;
|
9
9
|
|
10
|
-
|
10
|
+
restyledElement: (elementDescription: string) => string;
|
11
11
|
}
|
12
12
|
|
13
13
|
export const defaultComponentLocalization: ImageComponentLocalization = {
|
14
14
|
unlabeledImageNode: 'Unlabeled image node',
|
15
15
|
stroke: 'Stroke',
|
16
16
|
svgObject: 'SVG Object',
|
17
|
-
restyledElements: 'Restyled elements',
|
18
17
|
emptyBackground: 'Empty background',
|
19
18
|
filledBackgroundWithColor: (color) => `Filled background (${color})`,
|
20
19
|
text: (text) => `Text object: ${text}`,
|
21
20
|
imageNode: (description: string) => `Image: ${description}`,
|
21
|
+
restyledElement: (elementDescription: string) => `Restyled ${elementDescription}`,
|
22
22
|
};
|
package/src/lib.ts
CHANGED
@@ -30,6 +30,7 @@ export * from './toolbar/lib';
|
|
30
30
|
export * from './rendering/lib';
|
31
31
|
export { default as Pointer, PointerDevice } from './Pointer';
|
32
32
|
export { default as HTMLToolbar } from './toolbar/HTMLToolbar';
|
33
|
+
export { default as UndoRedoHistory } from './UndoRedoHistory';
|
33
34
|
|
34
35
|
export { Editor, EditorSettings };
|
35
36
|
export default Editor;
|
@@ -43,6 +43,9 @@ export default class HTMLToolbar {
|
|
43
43
|
private resizeObserver: ResizeObserver;
|
44
44
|
private listeners: DispatcherEventListener[] = [];
|
45
45
|
|
46
|
+
// Flex-order of the next widget to be added.
|
47
|
+
private widgetOrderCounter: number = 0;
|
48
|
+
|
46
49
|
private widgetsById: Record<string, BaseWidget> = {};
|
47
50
|
private widgetList: Array<BaseWidget> = [];
|
48
51
|
|
@@ -240,6 +243,7 @@ export default class HTMLToolbar {
|
|
240
243
|
}
|
241
244
|
}
|
242
245
|
|
246
|
+
|
243
247
|
/**
|
244
248
|
* Adds an `ActionButtonWidget` or `BaseToolWidget`. The widget should not have already have a parent
|
245
249
|
* (i.e. its `addTo` method should not have been called).
|
@@ -265,7 +269,7 @@ export default class HTMLToolbar {
|
|
265
269
|
|
266
270
|
// Ensure that the widget gets displayed in the correct
|
267
271
|
// place in the toolbar, even if it's removed and re-added.
|
268
|
-
container.style.order = `${this.
|
272
|
+
container.style.order = `${this.widgetOrderCounter++}`;
|
269
273
|
|
270
274
|
this.queueReLayout();
|
271
275
|
}
|
@@ -307,6 +311,7 @@ export default class HTMLToolbar {
|
|
307
311
|
spacer.style.maxWidth = options.maxSize;
|
308
312
|
}
|
309
313
|
|
314
|
+
spacer.style.order = `${this.widgetOrderCounter++}`;
|
310
315
|
this.container.appendChild(spacer);
|
311
316
|
}
|
312
317
|
|
package/src/toolbar/toolbar.css
CHANGED
@@ -18,6 +18,8 @@
|
|
18
18
|
flex-direction: row;
|
19
19
|
justify-content: center;
|
20
20
|
|
21
|
+
--toolbar-button-height: min(20vh, 60px);
|
22
|
+
|
21
23
|
/* Display above selection dialogs, etc. */
|
22
24
|
z-index: 2;
|
23
25
|
|
@@ -30,7 +32,7 @@
|
|
30
32
|
.toolbar-root > .toolbar-button {
|
31
33
|
width: min-content;
|
32
34
|
white-space: pre;
|
33
|
-
height:
|
35
|
+
height: var(--toolbar-button-height);
|
34
36
|
}
|
35
37
|
|
36
38
|
.toolbar-dropdown .toolbar-button > .toolbar-icon {
|
@@ -76,6 +78,10 @@
|
|
76
78
|
font-size: 1em;
|
77
79
|
}
|
78
80
|
|
81
|
+
.toolbar-button > label {
|
82
|
+
cursor: inherit;
|
83
|
+
}
|
84
|
+
|
79
85
|
.toolbar-dropdown > .toolbar-toolContainer > button,
|
80
86
|
.toolbar-dropdown > .toolbar-toolContainer > .toolbar-button {
|
81
87
|
width: 6em;
|
@@ -3,7 +3,25 @@
|
|
3
3
|
display: flex;
|
4
4
|
flex-direction: column;
|
5
5
|
flex-wrap: wrap;
|
6
|
+
justify-content: center;
|
7
|
+
}
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
.toolbar-overflow-widget-overflow-list > .toolbar-toolContainer > .toolbar-button {
|
10
|
+
height: var(--toolbar-button-height);
|
11
|
+
}
|
12
|
+
|
13
|
+
.toolbar-overflow-widget.horizontal .toolbar-overflow-widget-overflow-list {
|
14
|
+
flex-direction: row;
|
15
|
+
}
|
16
|
+
|
17
|
+
.toolbar-overflow-widget.horizontal > .toolbar-dropdown {
|
18
|
+
max-width: 100%;
|
19
|
+
left: 15px;
|
20
|
+
right: 15px;
|
21
|
+
|
22
|
+
/* Override the default transform and margin-left */
|
23
|
+
margin-left: 0 !important;
|
24
|
+
transform: none !important;
|
25
|
+
|
26
|
+
padding: 4px;
|
9
27
|
}
|
@@ -10,6 +10,9 @@ export default class OverflowWidget extends BaseWidget {
|
|
10
10
|
public constructor(editor: Editor, localizationTable?: ToolbarLocalization) {
|
11
11
|
super(editor, 'overflow-widget', localizationTable);
|
12
12
|
|
13
|
+
|
14
|
+
this.container.classList.add('toolbar-overflow-widget');
|
15
|
+
|
13
16
|
// Make the dropdown openable
|
14
17
|
this.container.classList.add('dropdownShowable');
|
15
18
|
this.overflowContainer ??= document.createElement('div');
|
@@ -44,6 +47,7 @@ export default class OverflowWidget extends BaseWidget {
|
|
44
47
|
*/
|
45
48
|
public clearChildren(): BaseWidget[] {
|
46
49
|
this.overflowContainer.replaceChildren();
|
50
|
+
this.container.classList.remove('horizontal');
|
47
51
|
|
48
52
|
const overflowChildren = this.overflowChildren;
|
49
53
|
this.overflowChildren = [];
|
@@ -73,6 +77,11 @@ export default class OverflowWidget extends BaseWidget {
|
|
73
77
|
this.overflowChildren.push(widget);
|
74
78
|
widget.addTo(this.overflowContainer);
|
75
79
|
widget.setIsToplevel(false);
|
80
|
+
|
81
|
+
// Switch to a horizontal layout if enough children
|
82
|
+
if (this.overflowChildren.length > 2) {
|
83
|
+
this.container.classList.add('horizontal');
|
84
|
+
}
|
76
85
|
}
|
77
86
|
|
78
87
|
// This always returns false.
|
package/src/types.ts
CHANGED
@@ -111,7 +111,6 @@ export type InputEvt = KeyPressEvent | KeyUpEvent | WheelEvt | GestureCancelEvt
|
|
111
111
|
|
112
112
|
export type EditorNotifier = EventDispatcher<EditorEventType, EditorEventDataType>;
|
113
113
|
|
114
|
-
|
115
114
|
export enum EditorEventType {
|
116
115
|
ToolEnabled,
|
117
116
|
ToolDisabled,
|
@@ -130,6 +129,13 @@ export enum EditorEventType {
|
|
130
129
|
ToolbarDropdownShown,
|
131
130
|
}
|
132
131
|
|
132
|
+
// Types of `EditorUndoStackUpdated` events.
|
133
|
+
export enum UndoEventType {
|
134
|
+
CommandDone,
|
135
|
+
CommandUndone,
|
136
|
+
CommandRedone,
|
137
|
+
}
|
138
|
+
|
133
139
|
type EditorToolEventType = EditorEventType.ToolEnabled
|
134
140
|
| EditorEventType.ToolDisabled
|
135
141
|
| EditorEventType.ToolUpdated;
|
@@ -159,8 +165,12 @@ export interface DisplayResizedEvent {
|
|
159
165
|
|
160
166
|
export interface EditorUndoStackUpdated {
|
161
167
|
readonly kind: EditorEventType.UndoRedoStackUpdated;
|
168
|
+
|
162
169
|
readonly undoStackSize: number;
|
163
170
|
readonly redoStackSize: number;
|
171
|
+
|
172
|
+
readonly command?: Command;
|
173
|
+
readonly stackUpdateType: UndoEventType;
|
164
174
|
}
|
165
175
|
|
166
176
|
export interface CommandDoneEvent {
|