@metadev/daga 4.2.15 → 4.2.16
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 +5 -0
- package/index.cjs.js +54 -47
- package/index.esm.js +54 -47
- package/package.json +1 -1
- package/src/lib/diagram/canvas/diagram-canvas.d.ts +1 -0
- package/src/lib/interfaces/canvas.d.ts +5 -0
package/Changelog.md
CHANGED
|
@@ -6,6 +6,11 @@ List of releases and changes.
|
|
|
6
6
|
|
|
7
7
|
## Next release Joyeuse
|
|
8
8
|
|
|
9
|
+
## v. 4.2.16
|
|
10
|
+
|
|
11
|
+
- Fix bug where the `DagaImporter` fails to create a node's label if it's blank [#373](https://github.com/metadevpro/daga/pull/373)
|
|
12
|
+
- Add `openTextInput` method to `Canvas` to enable opening a text box editor for a text via API [#374](https://github.com/metadevpro/daga/pull/374)
|
|
13
|
+
|
|
9
14
|
## v. 4.2.15
|
|
10
15
|
|
|
11
16
|
- Configure center animation duration in buttons component [#368](https://github.com/metadevpro/daga/pull/368)
|
package/index.cjs.js
CHANGED
|
@@ -1194,13 +1194,17 @@ const clone = o => {
|
|
|
1194
1194
|
if (typeof o !== 'object') {
|
|
1195
1195
|
return o;
|
|
1196
1196
|
}
|
|
1197
|
+
if (Array.isArray(o)) {
|
|
1198
|
+
return o.map(clone);
|
|
1199
|
+
}
|
|
1197
1200
|
const res = {};
|
|
1198
1201
|
for (const e of Object.entries(o)) {
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1202
|
+
res[e[0]] = clone(e[1]);
|
|
1203
|
+
// if (typeof e[1] === 'object') {
|
|
1204
|
+
// res[e[0]] = clone(e[1]);
|
|
1205
|
+
// } else {
|
|
1206
|
+
// res[e[0]] = e[1];
|
|
1207
|
+
// }
|
|
1204
1208
|
}
|
|
1205
1209
|
return res;
|
|
1206
1210
|
};
|
|
@@ -4946,23 +4950,21 @@ class DagaImporter {
|
|
|
4946
4950
|
model.nodes.add(newNode);
|
|
4947
4951
|
newNode.width = node.width;
|
|
4948
4952
|
newNode.height = node.height;
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4956
|
-
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
newField.updateInView();
|
|
4965
|
-
}
|
|
4953
|
+
// add node decorators
|
|
4954
|
+
if (newNodeType.decorators) {
|
|
4955
|
+
for (let i = 0; i < newNodeType.decorators.length; ++i) {
|
|
4956
|
+
const decoratorConfig = newNodeType.decorators[i];
|
|
4957
|
+
model.decorators.new(newNode, [newNode.coords[0] + decoratorConfig.coords[0], newNode.coords[1] + decoratorConfig.coords[1]], decoratorConfig.width, decoratorConfig.height, newNode.getPriority(), decoratorConfig.html, `${newNode.id}_decorator_${i}`);
|
|
4958
|
+
}
|
|
4959
|
+
}
|
|
4960
|
+
// add node label
|
|
4961
|
+
if (newNodeType.label) {
|
|
4962
|
+
const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), newNodeType.label);
|
|
4963
|
+
const newField = new DiagramField(model, newNode, [newNode.coords[0] + getLeftMargin(labelConfiguration), newNode.coords[1] + getTopMargin(labelConfiguration)], newNode.width - getLeftMargin(labelConfiguration) - getRightMargin(labelConfiguration), newNode.height - getTopMargin(labelConfiguration) - getBottomMargin(labelConfiguration), labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit, labelConfiguration.shrink);
|
|
4964
|
+
newField.text = node.label;
|
|
4965
|
+
newNode.label = newField;
|
|
4966
|
+
model.fields.add(newField);
|
|
4967
|
+
newField.updateInView();
|
|
4966
4968
|
}
|
|
4967
4969
|
for (const child of node.children || []) {
|
|
4968
4970
|
const newChild = this.importNode(model, child);
|
|
@@ -4975,16 +4977,14 @@ class DagaImporter {
|
|
|
4975
4977
|
const newSection = new DiagramSection(model, newNode, section.indexXInNode, section.indexYInNode, section.coords, section.width, section.height, section.id);
|
|
4976
4978
|
(_b = newNode.sections) === null || _b === void 0 ? void 0 : _b.push(newSection);
|
|
4977
4979
|
model.sections.add(newSection);
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
newField.updateInView();
|
|
4987
|
-
}
|
|
4980
|
+
// add section label
|
|
4981
|
+
if ((_f = (_e = (_d = (_c = newNodeType.sectionGrid) === null || _c === void 0 ? void 0 : _c.sections) === null || _d === void 0 ? void 0 : _d[section.indexYInNode]) === null || _e === void 0 ? void 0 : _e[section.indexXInNode]) === null || _f === void 0 ? void 0 : _f.label) {
|
|
4982
|
+
const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), (_k = (_j = (_h = (_g = newNodeType.sectionGrid) === null || _g === void 0 ? void 0 : _g.sections) === null || _h === void 0 ? void 0 : _h[section.indexYInNode]) === null || _j === void 0 ? void 0 : _j[section.indexXInNode]) === null || _k === void 0 ? void 0 : _k.label);
|
|
4983
|
+
const newField = new DiagramField(model, newSection, [newSection.coords[0] + getLeftMargin(labelConfiguration), newSection.coords[1] + getTopMargin(labelConfiguration)], newSection.width - getLeftMargin(labelConfiguration) - getRightMargin(labelConfiguration), newSection.height - getTopMargin(labelConfiguration) - getBottomMargin(labelConfiguration), labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit, labelConfiguration.shrink);
|
|
4984
|
+
newField.text = section.label;
|
|
4985
|
+
newSection.label = newField;
|
|
4986
|
+
model.fields.add(newField);
|
|
4987
|
+
newField.updateInView();
|
|
4988
4988
|
}
|
|
4989
4989
|
let portCounter = 0;
|
|
4990
4990
|
for (const port of section.ports || []) {
|
|
@@ -8722,21 +8722,7 @@ class DiagramCanvas {
|
|
|
8722
8722
|
this.diagramEvent$.next(diagramEvent);
|
|
8723
8723
|
if (!diagramEvent.defaultPrevented && this.canUserPerformAction(exports.DiagramActions.EditField) && d.editable && !d.removed) {
|
|
8724
8724
|
this.currentAction = new EditFieldAction(this, d.id, d.text, '');
|
|
8725
|
-
this.
|
|
8726
|
-
/*
|
|
8727
|
-
Empty for now
|
|
8728
|
-
We should create a better function to stretch the root element as the text expands
|
|
8729
|
-
Bear in mind that DiagramNode.setGeometry() calls DiagramNode.raise(), which breaks the input field
|
|
8730
|
-
*/
|
|
8731
|
-
}, text => {
|
|
8732
|
-
d.text = text;
|
|
8733
|
-
if (this.currentAction instanceof EditFieldAction) {
|
|
8734
|
-
this.currentAction.to = text;
|
|
8735
|
-
this.currentAction.do();
|
|
8736
|
-
this.actionStack.add(this.currentAction);
|
|
8737
|
-
this.currentAction = undefined;
|
|
8738
|
-
}
|
|
8739
|
-
});
|
|
8725
|
+
this.openTextInput(d.id);
|
|
8740
8726
|
}
|
|
8741
8727
|
}).call(d3__namespace.drag().filter(event => {
|
|
8742
8728
|
this.secondaryButton = isSecondaryButton(event);
|
|
@@ -9324,6 +9310,27 @@ class DiagramCanvas {
|
|
|
9324
9310
|
canUserPerformAction(action) {
|
|
9325
9311
|
return this.userActions[action] !== false;
|
|
9326
9312
|
}
|
|
9313
|
+
openTextInput(id) {
|
|
9314
|
+
const field = this.model.fields.get(id);
|
|
9315
|
+
if (field) {
|
|
9316
|
+
this.createInputField(field.text, field.coords, field.width, field.height, field.fontSize, field.fontFamily || DIAGRAM_FIELD_DEFAULTS.fontFamily, field.orientation, () => {
|
|
9317
|
+
// (_text)
|
|
9318
|
+
/*
|
|
9319
|
+
Empty for now
|
|
9320
|
+
We should create a better function to stretch the root element as the text expands
|
|
9321
|
+
Bear in mind that DiagramNode.setGeometry() calls DiagramNode.raise(), which breaks the input field
|
|
9322
|
+
*/
|
|
9323
|
+
}, text => {
|
|
9324
|
+
field.text = text;
|
|
9325
|
+
if (this.currentAction instanceof EditFieldAction) {
|
|
9326
|
+
this.currentAction.to = text;
|
|
9327
|
+
this.currentAction.do();
|
|
9328
|
+
this.actionStack.add(this.currentAction);
|
|
9329
|
+
this.currentAction = undefined;
|
|
9330
|
+
}
|
|
9331
|
+
});
|
|
9332
|
+
}
|
|
9333
|
+
}
|
|
9327
9334
|
createInputField(text, coords, width, height, fontSize, fontFamily, orientation, changeCallback, finishCallback) {
|
|
9328
9335
|
// if we have a text input open, close it before creating a new one
|
|
9329
9336
|
this.removeInputField();
|
package/index.esm.js
CHANGED
|
@@ -1173,13 +1173,17 @@ const clone = o => {
|
|
|
1173
1173
|
if (typeof o !== 'object') {
|
|
1174
1174
|
return o;
|
|
1175
1175
|
}
|
|
1176
|
+
if (Array.isArray(o)) {
|
|
1177
|
+
return o.map(clone);
|
|
1178
|
+
}
|
|
1176
1179
|
const res = {};
|
|
1177
1180
|
for (const e of Object.entries(o)) {
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1181
|
+
res[e[0]] = clone(e[1]);
|
|
1182
|
+
// if (typeof e[1] === 'object') {
|
|
1183
|
+
// res[e[0]] = clone(e[1]);
|
|
1184
|
+
// } else {
|
|
1185
|
+
// res[e[0]] = e[1];
|
|
1186
|
+
// }
|
|
1183
1187
|
}
|
|
1184
1188
|
return res;
|
|
1185
1189
|
};
|
|
@@ -4925,23 +4929,21 @@ class DagaImporter {
|
|
|
4925
4929
|
model.nodes.add(newNode);
|
|
4926
4930
|
newNode.width = node.width;
|
|
4927
4931
|
newNode.height = node.height;
|
|
4928
|
-
|
|
4929
|
-
|
|
4930
|
-
|
|
4931
|
-
|
|
4932
|
-
|
|
4933
|
-
|
|
4934
|
-
|
|
4935
|
-
|
|
4936
|
-
|
|
4937
|
-
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4942
|
-
|
|
4943
|
-
newField.updateInView();
|
|
4944
|
-
}
|
|
4932
|
+
// add node decorators
|
|
4933
|
+
if (newNodeType.decorators) {
|
|
4934
|
+
for (let i = 0; i < newNodeType.decorators.length; ++i) {
|
|
4935
|
+
const decoratorConfig = newNodeType.decorators[i];
|
|
4936
|
+
model.decorators.new(newNode, [newNode.coords[0] + decoratorConfig.coords[0], newNode.coords[1] + decoratorConfig.coords[1]], decoratorConfig.width, decoratorConfig.height, newNode.getPriority(), decoratorConfig.html, `${newNode.id}_decorator_${i}`);
|
|
4937
|
+
}
|
|
4938
|
+
}
|
|
4939
|
+
// add node label
|
|
4940
|
+
if (newNodeType.label) {
|
|
4941
|
+
const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), newNodeType.label);
|
|
4942
|
+
const newField = new DiagramField(model, newNode, [newNode.coords[0] + getLeftMargin(labelConfiguration), newNode.coords[1] + getTopMargin(labelConfiguration)], newNode.width - getLeftMargin(labelConfiguration) - getRightMargin(labelConfiguration), newNode.height - getTopMargin(labelConfiguration) - getBottomMargin(labelConfiguration), labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit, labelConfiguration.shrink);
|
|
4943
|
+
newField.text = node.label;
|
|
4944
|
+
newNode.label = newField;
|
|
4945
|
+
model.fields.add(newField);
|
|
4946
|
+
newField.updateInView();
|
|
4945
4947
|
}
|
|
4946
4948
|
for (const child of node.children || []) {
|
|
4947
4949
|
const newChild = this.importNode(model, child);
|
|
@@ -4954,16 +4956,14 @@ class DagaImporter {
|
|
|
4954
4956
|
const newSection = new DiagramSection(model, newNode, section.indexXInNode, section.indexYInNode, section.coords, section.width, section.height, section.id);
|
|
4955
4957
|
(_b = newNode.sections) === null || _b === void 0 ? void 0 : _b.push(newSection);
|
|
4956
4958
|
model.sections.add(newSection);
|
|
4957
|
-
|
|
4958
|
-
|
|
4959
|
-
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
|
|
4963
|
-
|
|
4964
|
-
|
|
4965
|
-
newField.updateInView();
|
|
4966
|
-
}
|
|
4959
|
+
// add section label
|
|
4960
|
+
if ((_f = (_e = (_d = (_c = newNodeType.sectionGrid) === null || _c === void 0 ? void 0 : _c.sections) === null || _d === void 0 ? void 0 : _d[section.indexYInNode]) === null || _e === void 0 ? void 0 : _e[section.indexXInNode]) === null || _f === void 0 ? void 0 : _f.label) {
|
|
4961
|
+
const labelConfiguration = Object.assign(Object.assign({}, DIAGRAM_FIELD_DEFAULTS), (_k = (_j = (_h = (_g = newNodeType.sectionGrid) === null || _g === void 0 ? void 0 : _g.sections) === null || _h === void 0 ? void 0 : _h[section.indexYInNode]) === null || _j === void 0 ? void 0 : _j[section.indexXInNode]) === null || _k === void 0 ? void 0 : _k.label);
|
|
4962
|
+
const newField = new DiagramField(model, newSection, [newSection.coords[0] + getLeftMargin(labelConfiguration), newSection.coords[1] + getTopMargin(labelConfiguration)], newSection.width - getLeftMargin(labelConfiguration) - getRightMargin(labelConfiguration), newSection.height - getTopMargin(labelConfiguration) - getBottomMargin(labelConfiguration), labelConfiguration.fontSize, labelConfiguration.fontFamily, labelConfiguration.color, labelConfiguration.selectedColor, labelConfiguration.horizontalAlign, labelConfiguration.verticalAlign, labelConfiguration.orientation, '', labelConfiguration.editable, labelConfiguration.fit, labelConfiguration.shrink);
|
|
4963
|
+
newField.text = section.label;
|
|
4964
|
+
newSection.label = newField;
|
|
4965
|
+
model.fields.add(newField);
|
|
4966
|
+
newField.updateInView();
|
|
4967
4967
|
}
|
|
4968
4968
|
let portCounter = 0;
|
|
4969
4969
|
for (const port of section.ports || []) {
|
|
@@ -8701,21 +8701,7 @@ class DiagramCanvas {
|
|
|
8701
8701
|
this.diagramEvent$.next(diagramEvent);
|
|
8702
8702
|
if (!diagramEvent.defaultPrevented && this.canUserPerformAction(DiagramActions.EditField) && d.editable && !d.removed) {
|
|
8703
8703
|
this.currentAction = new EditFieldAction(this, d.id, d.text, '');
|
|
8704
|
-
this.
|
|
8705
|
-
/*
|
|
8706
|
-
Empty for now
|
|
8707
|
-
We should create a better function to stretch the root element as the text expands
|
|
8708
|
-
Bear in mind that DiagramNode.setGeometry() calls DiagramNode.raise(), which breaks the input field
|
|
8709
|
-
*/
|
|
8710
|
-
}, text => {
|
|
8711
|
-
d.text = text;
|
|
8712
|
-
if (this.currentAction instanceof EditFieldAction) {
|
|
8713
|
-
this.currentAction.to = text;
|
|
8714
|
-
this.currentAction.do();
|
|
8715
|
-
this.actionStack.add(this.currentAction);
|
|
8716
|
-
this.currentAction = undefined;
|
|
8717
|
-
}
|
|
8718
|
-
});
|
|
8704
|
+
this.openTextInput(d.id);
|
|
8719
8705
|
}
|
|
8720
8706
|
}).call(d3.drag().filter(event => {
|
|
8721
8707
|
this.secondaryButton = isSecondaryButton(event);
|
|
@@ -9303,6 +9289,27 @@ class DiagramCanvas {
|
|
|
9303
9289
|
canUserPerformAction(action) {
|
|
9304
9290
|
return this.userActions[action] !== false;
|
|
9305
9291
|
}
|
|
9292
|
+
openTextInput(id) {
|
|
9293
|
+
const field = this.model.fields.get(id);
|
|
9294
|
+
if (field) {
|
|
9295
|
+
this.createInputField(field.text, field.coords, field.width, field.height, field.fontSize, field.fontFamily || DIAGRAM_FIELD_DEFAULTS.fontFamily, field.orientation, () => {
|
|
9296
|
+
// (_text)
|
|
9297
|
+
/*
|
|
9298
|
+
Empty for now
|
|
9299
|
+
We should create a better function to stretch the root element as the text expands
|
|
9300
|
+
Bear in mind that DiagramNode.setGeometry() calls DiagramNode.raise(), which breaks the input field
|
|
9301
|
+
*/
|
|
9302
|
+
}, text => {
|
|
9303
|
+
field.text = text;
|
|
9304
|
+
if (this.currentAction instanceof EditFieldAction) {
|
|
9305
|
+
this.currentAction.to = text;
|
|
9306
|
+
this.currentAction.do();
|
|
9307
|
+
this.actionStack.add(this.currentAction);
|
|
9308
|
+
this.currentAction = undefined;
|
|
9309
|
+
}
|
|
9310
|
+
});
|
|
9311
|
+
}
|
|
9312
|
+
}
|
|
9306
9313
|
createInputField(text, coords, width, height, fontSize, fontFamily, orientation, changeCallback, finishCallback) {
|
|
9307
9314
|
// if we have a text input open, close it before creating a new one
|
|
9308
9315
|
this.removeInputField();
|
package/package.json
CHANGED
|
@@ -138,6 +138,7 @@ export declare class DiagramCanvas implements Canvas {
|
|
|
138
138
|
private dropConnection;
|
|
139
139
|
cancelAllUserActions(): void;
|
|
140
140
|
canUserPerformAction(action: DiagramActions): boolean;
|
|
141
|
+
openTextInput(id: string): void;
|
|
141
142
|
private createInputField;
|
|
142
143
|
private removeInputField;
|
|
143
144
|
private minimumSizeOfField;
|
|
@@ -356,6 +356,11 @@ export interface Canvas {
|
|
|
356
356
|
* @param shrink Whether the node should shrink if there is excess space; `true` by default
|
|
357
357
|
*/
|
|
358
358
|
fitNodeInView(id: string, shrink?: boolean): void;
|
|
359
|
+
/**
|
|
360
|
+
* Open a text input for a field.
|
|
361
|
+
* @param id The id of a field.
|
|
362
|
+
*/
|
|
363
|
+
openTextInput(id: string): void;
|
|
359
364
|
/**
|
|
360
365
|
* Get the d3 Selection containing the root html div element of the canvas.
|
|
361
366
|
* @private
|