@peter.prib/renderengine 0.2.5 → 0.2.7
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/README.md +219 -213
- package/REFERENCE.md +272 -6
- package/dist/renderengine-workspace.umd.js +11980 -7421
- package/dist/renderengine.umd.js +8991 -5784
- package/examples/archimate.html +68 -66
- package/examples/data-model.html +534 -0
- package/package.json +70 -68
- package/src/bian.js +182 -0
- package/src/charting/CheckboxTreeSelector.js +373 -304
- package/src/charting/DiagramEditor.js +53 -32
- package/src/charting/DiagramTypeRegistry.js +13 -3
- package/src/charting/ModelCheckDialog.js +63 -0
- package/src/charting/ModelChecker.js +26 -0
- package/src/charting/ViewTabStrip.js +94 -81
- package/src/charting/archimate/ArchimateCanvasEditor.js +825 -815
- package/src/charting/archimate/ArchimateElementTemplate.js +208 -195
- package/src/charting/datamodel/BianLandscapeReader.js +185 -0
- package/src/charting/datamodel/BianSemanticApiReader.js +183 -0
- package/src/charting/datamodel/DataModel.js +645 -0
- package/src/charting/datamodel/DataModelChecker.js +92 -0
- package/src/charting/datamodel/DataModelCompared.js +127 -0
- package/src/charting/datamodel/DataModelContext.js +108 -0
- package/src/charting/datamodel/DataModelFileFormat.js +33 -0
- package/src/charting/datamodel/DataModelPerspective.js +129 -0
- package/src/charting/datamodel/DataType.js +108 -0
- package/src/charting/datamodel/EnumerationType.js +51 -0
- package/src/charting/datamodel/LevelMapping.js +38 -0
- package/src/charting/datamodel/LevelSchema.js +41 -0
- package/src/charting/datamodel/ServiceDomain.js +177 -0
- package/src/charting/datamodel/ServiceLandscape.js +104 -0
- package/src/charting/datamodel/StructuredType.js +63 -0
- package/src/charting/datamodel/index.js +15 -0
- package/src/charting/diagramModel/MergeModelCommand.js +43 -37
- package/src/charting/diagramModel/OpenViewList.js +75 -0
- package/src/charting/diagramModel/ViewSetChecker.js +22 -34
- package/src/charting/diagrams/DataModelDiagram.js +160 -86
- package/src/charting/diagrams/DataModelRelationshipStrategy.js +94 -38
- package/src/charting/diagrams/EdgeGeometry.js +578 -553
- package/src/charting/diagrams/GraphDiagram.js +11 -1
- package/src/charting/diagrams/NodeGeometry.js +169 -158
- package/src/charting/diagrams/nesting.js +31 -0
- package/src/charting/glyphs/PersonGlyph.js +24 -23
- package/src/charting/modelTree/ModelTree.js +202 -164
- package/src/charting/modelTree/ModelTreePanel.js +36 -3
- package/src/charting/modelTree/TreeViewMode.js +131 -110
- package/src/charting/modelTree/modes/FlatTreeMode.js +32 -46
- package/src/charting/modelTree/modes/LayerGroupedTreeMode.js +47 -62
- package/src/charting/modelTree/modes/TypeGroupedTreeMode.js +46 -60
- package/src/datamodel.js +132 -122
- package/src/diagramCatalog.js +35 -30
- package/src/index.js +2666 -2659
- package/src/workspace/EditorShell.js +166 -67
- package/src/workspace/PanelLayout.js +56 -0
- package/src/workspace/index.js +1 -0
- package/src/workspace/layout/TabsNode.js +205 -191
- package/src/workspace/parts/ArchimateCanvasPart.js +10 -9
- package/src/workspace/parts/ChartPart.js +6 -1
- package/src/workspace/parts/DataModelPart.js +544 -0
- package/src/workspace/parts/DiagramEditorPart.js +2 -8
- package/src/workspace/parts/EditorPart.js +461 -407
- package/src/workspace/parts/ModelFile.js +216 -187
- package/src/workspace/parts/ModelsPart.js +483 -192
- package/src/workspace/storage/BackupFolder.js +145 -0
- package/src/workspace/storage/KeyValueStore.js +92 -0
- package/src/workspace/storage/ModelLibrary.js +65 -0
- package/src/workspace/workArea.js +417 -413
- package/src/yaml/YamlReader.js +372 -0
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
import { ChartPart } from './ChartPart.js';
|
|
2
|
+
import { el } from '../dom.js';
|
|
3
|
+
import { MenuBar } from '../../charting/MenuBar.js';
|
|
4
|
+
import { ToolbarSelect, ToolbarMenu, ToolbarText } from '../../charting/toolbar/index.js';
|
|
5
|
+
import { FormDialog } from '../../charting/FormDialog.js';
|
|
6
|
+
import { ModelCheckDialog } from '../../charting/ModelCheckDialog.js';
|
|
7
|
+
import { DataModelNotation } from '../../datamodel.js';
|
|
8
|
+
import {
|
|
9
|
+
DataModel, DataModelPerspective, DataModelContext, DataModelFileFormat, ServiceDomain, ServiceLandscape, BianLandscapeReader,
|
|
10
|
+
BianSemanticApiReader, DataType, EnumerationType, StructuredType,
|
|
11
|
+
} from '../../charting/datamodel/index.js';
|
|
12
|
+
import { pickFile } from '../../charting/toolbar/pickFile.js';
|
|
13
|
+
import { ModelFile } from './ModelFile.js';
|
|
14
|
+
import { EditorPart } from './EditorPart.js';
|
|
15
|
+
import { downloadPng, downloadSvg } from '../../exportImage.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* DataModelPart — a data model (DataModel, drawn by dataModelDiagram) in a
|
|
19
|
+
* pane: its conceptual, logical and physical levels, each its own schema, and
|
|
20
|
+
* how they map; seen through a perspective (whose concepts, under whose names)
|
|
21
|
+
* read in a context (what they mean here, the rules that hold, where and
|
|
22
|
+
* when), in a notation (Chen, Crow's Foot, UML). Its toolbar switches each
|
|
23
|
+
* of them, Level offering the views that are no level (DataModel.OTHER_VIEWS:
|
|
24
|
+
* Mapping, the levels side by side joined where they map; Service landscape,
|
|
25
|
+
* the service domains in their business areas and domains, a double-click
|
|
26
|
+
* seeing the model through one), and its Model menu makes, changes and removes
|
|
27
|
+
* perspectives and contexts and reads service domains from a BIAN landscape. Boxes and notes stay where they were dragged. Export ▸ saves the
|
|
28
|
+
* picture (PNG, SVG). The drawing, its sizing and redrawing on resize are
|
|
29
|
+
* ChartPart's.
|
|
30
|
+
*
|
|
31
|
+
* It is saved as a file (DataModelFileFormat, `.datamodel.json`) as an
|
|
32
|
+
* editor's model is (ModelFile): File ▸ Open…, Save, Save As… (Ctrl+O, Ctrl+S),
|
|
33
|
+
* • while changed since, and asking before the page is left with changes
|
|
34
|
+
* unsaved. Hosted by a ModelsPart (`editorType: 'data-model'`) it is one of
|
|
35
|
+
* several models open, a tab each, and with that part's `keep` it is kept in
|
|
36
|
+
* this browser and backed up (File ▸ This browser), as the modeller's are.
|
|
37
|
+
*
|
|
38
|
+
* Spec: `{ id, type: 'data-model', title?, levels?, mappings?, mappingLayout?,
|
|
39
|
+
* perspectives?, contexts?, perspective?, context?, level?, notation?, options? }`
|
|
40
|
+
* — the model as DataModel takes it (or `entities`/`relationships` in the older
|
|
41
|
+
* one-entity form); `perspective`/`context` the ids chosen; `level` default
|
|
42
|
+
* 'logical' ('mapping' for the mapping view), `notation` default 'crowsfoot';
|
|
43
|
+
* `options` anything else dataModelDiagram takes (editable, resizable by default).
|
|
44
|
+
*/
|
|
45
|
+
export class DataModelPart extends ChartPart {
|
|
46
|
+
static type = 'data-model';
|
|
47
|
+
|
|
48
|
+
constructor(spec = {}) {
|
|
49
|
+
const { perspective = null, context = null, level = 'logical', notation = 'crowsfoot', options = {} } = spec;
|
|
50
|
+
super({ ...spec, chartType: 'dataModel', options: { editable: true, resizable: true, ...options, level, notation } });
|
|
51
|
+
/** The file it is open from and saved to. */
|
|
52
|
+
this.file = new ModelFile(this);
|
|
53
|
+
/** Its id among the models kept in this browser, or null. */
|
|
54
|
+
this.keepId = spec.keepId ?? null;
|
|
55
|
+
this._adoptModel(new DataModel(spec));
|
|
56
|
+
/** The ids chosen, or null. */
|
|
57
|
+
this.perspectiveId = perspective;
|
|
58
|
+
this.contextId = context ?? this.model.perspective(perspective)?.context ?? null;
|
|
59
|
+
/** The level the drawing on screen is of (where a drag is kept). */
|
|
60
|
+
this._drawnLevel = level;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ===== A model saved as a file, kept, backed up =====
|
|
64
|
+
|
|
65
|
+
/** Its file formats: the data model's own. */
|
|
66
|
+
fileFormats() {
|
|
67
|
+
return [DataModelFileFormat.instance ??= new DataModelFileFormat()];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
saveFormat() {
|
|
71
|
+
return this.fileFormats()[0];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The ModelsPart it is a tab of, or null. */
|
|
75
|
+
get modelsHost() {
|
|
76
|
+
return this.ctx?.models ?? null;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The page it is in. */
|
|
80
|
+
get document() {
|
|
81
|
+
return this.container?.ownerDocument ?? globalThis.document;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** What its tab and the page title show: the file's name (or the model's), and • while changed. */
|
|
85
|
+
get fileLabel() {
|
|
86
|
+
return this.file.label;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The model as kept in this browser (ModelFile#keepEntry). */
|
|
90
|
+
keepEntry() {
|
|
91
|
+
return this.file.keepEntry();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** Edit another model (one opened, imported or kept), from scratch: nothing chosen, nothing changed. */
|
|
95
|
+
replaceModel(model) {
|
|
96
|
+
this._adoptModel(model);
|
|
97
|
+
this.perspectiveId = null;
|
|
98
|
+
this.contextId = null;
|
|
99
|
+
if (this.mounted) this.render();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** A model opened from a file in a host's new tab (as EditorPart does). */
|
|
103
|
+
onImported(model) {
|
|
104
|
+
return EditorPart.prototype.onImported.call(this, model);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The file or its saved state changed: a ModelsPart's tab follows it. */
|
|
108
|
+
onFileState() {
|
|
109
|
+
this.modelsHost?.fileStateChanged?.(this);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Edit `model`: every change of it shows (• and the title) and is kept. @private */
|
|
113
|
+
_adoptModel(model) {
|
|
114
|
+
this._unsubscribeEdits?.();
|
|
115
|
+
this.model = model;
|
|
116
|
+
model.markSaved();
|
|
117
|
+
this._unsubscribeEdits = model.onEdit(() => {
|
|
118
|
+
this.file.showState();
|
|
119
|
+
this.modelsHost?.modelEdited?.(this);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
mount(host, ctx) {
|
|
124
|
+
const first = !this.mounted;
|
|
125
|
+
super.mount(host, ctx);
|
|
126
|
+
if (first) {
|
|
127
|
+
this.file.listen();
|
|
128
|
+
this.file.showState();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* File ▸: Open…, Save, Save As…, then with a ModelsPart New model and Close
|
|
134
|
+
* model, and This browser ▸ (keeping and backups).
|
|
135
|
+
*/
|
|
136
|
+
fileItems() {
|
|
137
|
+
const host = this.modelsHost;
|
|
138
|
+
return EditorPart.tidyMenu([
|
|
139
|
+
...this.file.menuItems(),
|
|
140
|
+
...(host ? [
|
|
141
|
+
{ separator: true },
|
|
142
|
+
...EditorPart.menuGroup('New', [{ label: 'New model', action: () => host.newModel() }, ...(host.baseItems?.() ?? [])]),
|
|
143
|
+
{ label: 'Duplicate model', action: () => host.duplicate(this) },
|
|
144
|
+
{ label: 'Close model', action: () => host.closeModel(this.id) },
|
|
145
|
+
...EditorPart.menuGroup('This browser', host.keepItems?.(this) ?? []),
|
|
146
|
+
] : []),
|
|
147
|
+
]);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Edit ▸: undo and redo (a merge is one step). */
|
|
151
|
+
editItems() {
|
|
152
|
+
const history = this.model.history;
|
|
153
|
+
return [
|
|
154
|
+
{ label: history.canUndo ? `Undo ${history.undoLabel}` : 'Undo', disabled: !history.canUndo || undefined, action: () => { history.undo(); this._redraw(); } },
|
|
155
|
+
{ label: history.canRedo ? `Redo ${history.redoLabel}` : 'Redo', disabled: !history.canRedo || undefined, action: () => { history.redo(); this._redraw(); } },
|
|
156
|
+
];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/** Run a model-wide edit (a merge) as one undo step, then redraw. */
|
|
160
|
+
runModelEdit(command) {
|
|
161
|
+
if (!command) return null;
|
|
162
|
+
this.model.history.execute(command);
|
|
163
|
+
this._changed();
|
|
164
|
+
this._redraw();
|
|
165
|
+
return command;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** The entities at the level shown (the concepts in the mapping view). */
|
|
169
|
+
get entities() {
|
|
170
|
+
return this.model.level(DataModel.otherView(this.level) ? 'conceptual' : this.level).entities;
|
|
171
|
+
}
|
|
172
|
+
get level() { return this.chartOptions.level; }
|
|
173
|
+
get notation() { return this.chartOptions.notation; }
|
|
174
|
+
/** The perspective chosen (DataModelPerspective), or null. */
|
|
175
|
+
get perspective() { return this.model.perspective(this.perspectiveId); }
|
|
176
|
+
/** The context chosen (DataModelContext), or null. */
|
|
177
|
+
get context() { return this.model.context(this.contextId); }
|
|
178
|
+
|
|
179
|
+
/** Show another level ('conceptual', 'logical', 'physical'), or how they map ('mapping'). */
|
|
180
|
+
setLevel(level) {
|
|
181
|
+
this.chartOptions.level = level;
|
|
182
|
+
this._redraw();
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/** Draw the model in another notation ('chen', 'crowsfoot', 'uml'). */
|
|
186
|
+
setNotation(notation) {
|
|
187
|
+
this.chartOptions.notation = notation;
|
|
188
|
+
this._redraw();
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** See the model through a perspective (an id; null: the whole schema), in the context it is read in, if it names one. */
|
|
192
|
+
setPerspective(id) {
|
|
193
|
+
this.perspectiveId = id || null;
|
|
194
|
+
const own = this.perspective?.context;
|
|
195
|
+
if (own) this.contextId = own;
|
|
196
|
+
this._redraw();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Read the model in a context (an id; null: the schema's own descriptions). */
|
|
200
|
+
setContext(id) {
|
|
201
|
+
this.contextId = id || null;
|
|
202
|
+
this._redraw();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** What is drawn: the perspective's view of the level (or the mapping) in the context (DataModel#view), in the notation. */
|
|
206
|
+
drawOptions() {
|
|
207
|
+
return {
|
|
208
|
+
...this.chartOptions,
|
|
209
|
+
...this.model.view({ perspective: this.perspectiveId, context: this.contextId, level: this.level }),
|
|
210
|
+
...(this.level === DataModel.LANDSCAPE && { onNodeDoubleClick: (node) => this.openServiceDomain(ServiceLandscape.serviceDomainOf(node.id)) }),
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** See the model through a service domain (an id), at the logical level, where its business objects are. */
|
|
215
|
+
openServiceDomain(id) {
|
|
216
|
+
if (!this.model.perspective(id)) return;
|
|
217
|
+
this.chartOptions.level = 'logical';
|
|
218
|
+
this.setPerspective(id);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
render() {
|
|
222
|
+
Object.assign(this.container.style, { display: 'flex', flexDirection: 'column', height: '100%' });
|
|
223
|
+
const toolbar = this.container.appendChild(el({}));
|
|
224
|
+
super.render();
|
|
225
|
+
Object.assign(this.canvasHost.style, { flex: '1 1 auto', minHeight: '0', height: 'auto' });
|
|
226
|
+
this.menuBar = new MenuBar({ container: toolbar, items: this.menuBarItems(), document: this.container.ownerDocument }).render();
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Model ▸ (perspectives and contexts of one's own), Perspective and Context
|
|
231
|
+
* (when the model has any; the context's scope beside them), Level (each
|
|
232
|
+
* level from DataModelNotation, then Mapping) and Notation, and Export ▸.
|
|
233
|
+
*/
|
|
234
|
+
menuBarItems() {
|
|
235
|
+
const { perspectives, contexts } = this.model;
|
|
236
|
+
const host = this.modelsHost;
|
|
237
|
+
return [
|
|
238
|
+
new ToolbarMenu('File', () => this.fileItems()),
|
|
239
|
+
new ToolbarMenu('Edit', () => this.editItems()),
|
|
240
|
+
...(host ? [new ToolbarMenu('Tools', () => host.toolItems(this))] : []),
|
|
241
|
+
new ToolbarMenu('Model', () => this.modelItems()),
|
|
242
|
+
...(perspectives.length ? [new ToolbarSelect('Perspective',
|
|
243
|
+
() => [['', 'Whole schema'], ...this.model.perspectives.map(p => [p.id, p.constructor === DataModelPerspective ? p.name : `${p.name} (${p.constructor.kindLabel.toLowerCase()})`, p.description])],
|
|
244
|
+
() => this.perspectiveId ?? '', (v) => this.setPerspective(v))] : []),
|
|
245
|
+
...(contexts.length ? [
|
|
246
|
+
new ToolbarSelect('Context',
|
|
247
|
+
() => [['', 'None'], ...this.model.contexts.map(c => [c.id, c.name, c.description])],
|
|
248
|
+
() => this.contextId ?? '', (v) => this.setContext(v)),
|
|
249
|
+
new ToolbarText(() => this.context?.scope ?? ''),
|
|
250
|
+
] : []),
|
|
251
|
+
new ToolbarSelect('Level', () => [
|
|
252
|
+
...DataModelNotation.levels().map(l => [l.name, l.label, l.description]),
|
|
253
|
+
...DataModel.OTHER_VIEWS.filter(v => v.offered(this.model) || v.name === this.level).map(v => [v.name, v.label, v.description]),
|
|
254
|
+
], () => this.level, (v) => this.setLevel(v)),
|
|
255
|
+
new ToolbarSelect('Notation', () => DataModelNotation.notations().map(n => [n.name, n.label]), () => this.notation, (v) => this.setNotation(v)),
|
|
256
|
+
new ToolbarMenu('Export', () => this.exportItems()),
|
|
257
|
+
];
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Model ▸: make, change or remove a perspective or a context (the one chosen). */
|
|
261
|
+
modelItems() {
|
|
262
|
+
return [
|
|
263
|
+
{ label: 'New perspective…', action: () => this.editPerspective(null) },
|
|
264
|
+
{ label: 'New service domain…', action: () => this.editPerspective(null, ServiceDomain) },
|
|
265
|
+
{ label: 'Read service domains from a BIAN landscape…', action: () => this.readLandscape() },
|
|
266
|
+
{ label: 'Read a BIAN service domain (semantic API)…', action: () => this.readSemanticApi() },
|
|
267
|
+
{ label: 'Edit perspective…', disabled: !this.perspective || undefined, action: () => this.editPerspective(this.perspective) },
|
|
268
|
+
{ label: 'Delete perspective', disabled: !this.perspective || undefined, action: () => this.removePerspective(this.perspectiveId) },
|
|
269
|
+
{ separator: true },
|
|
270
|
+
...EditorPart.menuGroup('Data types', this.dataTypeItems()),
|
|
271
|
+
{ separator: true },
|
|
272
|
+
{ label: 'New context…', action: () => this.editContext(null) },
|
|
273
|
+
{ label: 'Edit context…', disabled: !this.context || undefined, action: () => this.editContext(this.context) },
|
|
274
|
+
{ label: 'Delete context', disabled: !this.context || undefined, action: () => this.removeContext(this.contextId) },
|
|
275
|
+
{ separator: true },
|
|
276
|
+
{ label: 'Check model…', action: () => this.checkModel() },
|
|
277
|
+
];
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Service domains from BIAN's published service landscape (an ArchiMate
|
|
282
|
+
* model: an Archi file or the Exchange Format; BianLandscapeReader), as one
|
|
283
|
+
* undo step (DataModel#serviceDomainsCommand); then the landscape is shown.
|
|
284
|
+
* @param {Object} [options] - As readInto's, and `reader` (a BianLandscapeReader)
|
|
285
|
+
* @returns {Promise<Command|null>}
|
|
286
|
+
*/
|
|
287
|
+
readLandscape({ reader = new BianLandscapeReader(), ...options } = {}) {
|
|
288
|
+
let found = 0;
|
|
289
|
+
return this.readInto({
|
|
290
|
+
...options, accept: '.archimate,.xml', what: 'the landscape',
|
|
291
|
+
command: (bytes, name) => {
|
|
292
|
+
const specs = reader.read(BianLandscapeReader.parse(bytes));
|
|
293
|
+
found = specs.length;
|
|
294
|
+
return this.model.serviceDomainsCommand(specs, `"${name}"`);
|
|
295
|
+
},
|
|
296
|
+
nothing: (name) => (found
|
|
297
|
+
? `"${name}" brings nothing new: its ${found} service domain${found === 1 ? ' is' : 's are'} here as ${found === 1 ? 'it is' : 'they are'}.`
|
|
298
|
+
: `"${name}" has no service domains (Capabilities with none inside them).`),
|
|
299
|
+
then: () => { this.chartOptions.level = DataModel.LANDSCAPE; this.perspectiveId = null; },
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* A service domain from one of BIAN's semantic APIs (an OpenAPI file, YAML
|
|
305
|
+
* or JSON; BianSemanticApiReader): its control record and behaviour
|
|
306
|
+
* qualifiers as logical entities, the schemas they use as data types, and
|
|
307
|
+
* the service domain, as one undo step (DataModel#bringCommand); then the
|
|
308
|
+
* model is seen through it at the logical level. An entity the model has
|
|
309
|
+
* by name stays as it is and is used.
|
|
310
|
+
* @param {Object} [options] - As readInto's, and `depth` (BianSemanticApiReader's)
|
|
311
|
+
* @returns {Promise<Command|null>}
|
|
312
|
+
*/
|
|
313
|
+
readSemanticApi({ depth = 1, ...options } = {}) {
|
|
314
|
+
let read = null;
|
|
315
|
+
return this.readInto({
|
|
316
|
+
...options, accept: '.yaml,.yml,.json', what: 'the semantic API',
|
|
317
|
+
command: (bytes, name) => {
|
|
318
|
+
const reader = new BianSemanticApiReader({ depth, entityNames: this.model.level('logical').entities.map(e => e.name) });
|
|
319
|
+
read = reader.read(BianSemanticApiReader.parse(new TextDecoder().decode(bytes)));
|
|
320
|
+
const [sd] = read.serviceDomains;
|
|
321
|
+
return this.model.bringCommand(read, `Read ${sd.name} from "${name}"`);
|
|
322
|
+
},
|
|
323
|
+
nothing: (name) => `"${name}" brings nothing the model does not have.`,
|
|
324
|
+
then: () => {
|
|
325
|
+
// The service domain is the one here of its id or name (bringCommand keeps it), else the new one.
|
|
326
|
+
const [sd] = read.serviceDomains;
|
|
327
|
+
const here = this.model.perspective(sd.id) ?? this.model.perspectives.find(p => p.name.toLowerCase() === sd.name.toLowerCase());
|
|
328
|
+
this.chartOptions.level = 'logical';
|
|
329
|
+
this.perspectiveId = here?.id ?? sd.id;
|
|
330
|
+
},
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Ask for a file, make a command from its bytes, and run it as one undo
|
|
336
|
+
* step; a file that cannot be read, or brings nothing, is reported.
|
|
337
|
+
* @param {Object} how
|
|
338
|
+
* @param {string} how.accept - The file chooser's filter
|
|
339
|
+
* @param {string} how.what - What is read, for the report ('the landscape')
|
|
340
|
+
* @param {(bytes: Uint8Array, name: string) => Command|null} how.command
|
|
341
|
+
* @param {(name: string) => string} how.nothing - The report when the command is null
|
|
342
|
+
* @param {() => void} [how.then] - What to show once it is run (before the redraw)
|
|
343
|
+
* @param {(accept: string) => Promise<File|null>} [how.chooseFile]
|
|
344
|
+
* @param {(message: string) => void} [how.report]
|
|
345
|
+
* @returns {Promise<Command|null>}
|
|
346
|
+
*/
|
|
347
|
+
async readInto({ accept, what, command: make, nothing, then = () => {}, chooseFile = null, report = null }) {
|
|
348
|
+
const doc = this.container?.ownerDocument ?? globalThis.document;
|
|
349
|
+
const tell = report ?? ((message) => (doc.defaultView ?? globalThis).alert(message));
|
|
350
|
+
const file = await (chooseFile ?? ((filter) => pickFile(filter, doc)))(accept);
|
|
351
|
+
if (!file) return null;
|
|
352
|
+
let command;
|
|
353
|
+
try {
|
|
354
|
+
command = make(new Uint8Array(await file.arrayBuffer()), file.name);
|
|
355
|
+
} catch (err) {
|
|
356
|
+
tell(`Could not read ${what}: ${err.message}`);
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
if (!command) {
|
|
360
|
+
tell(nothing(file.name));
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
then();
|
|
364
|
+
this.runModelEdit(command);
|
|
365
|
+
return command;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** Model ▸ Data types ▸: a new one of each kind, then each to change or remove. */
|
|
369
|
+
dataTypeItems() {
|
|
370
|
+
const types = this.model.dataTypes;
|
|
371
|
+
return [
|
|
372
|
+
...[EnumerationType, StructuredType, DataType].map(Kind => ({ label: `New ${Kind.kindLabel.toLowerCase()}…`, action: () => this.editDataType(null, Kind) })),
|
|
373
|
+
...(types.length ? [
|
|
374
|
+
{ separator: true },
|
|
375
|
+
{ label: 'Show data types', action: () => this.setLevel(DataModel.DATA_TYPES) },
|
|
376
|
+
{ label: 'Edit', items: types.map(t => ({ label: `${t.name} (${t.constructor.kindLabel.toLowerCase()})…`, action: () => this.editDataType(t) })) },
|
|
377
|
+
{ label: 'Delete', items: types.map(t => ({ label: t.name, action: () => this.removeDataType(t.id) })) },
|
|
378
|
+
] : []),
|
|
379
|
+
];
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/** A dialog making a data type of a kind (none given) or changing one (its kind's fields); applied, the data types are shown. */
|
|
383
|
+
editDataType(type, Kind = type?.constructor ?? DataType) {
|
|
384
|
+
const title = type ? `${Kind.kindLabel}: ${type.name}` : `New ${Kind.kindLabel.toLowerCase()}`;
|
|
385
|
+
return this._dialog(title, Kind.fields(this.model, type), (values) => {
|
|
386
|
+
const spec = Kind.specFrom(values, this.model, type);
|
|
387
|
+
if (type) this.model.updateDataType(type.id, spec); else this.model.addDataType(spec);
|
|
388
|
+
this.chartOptions.level = DataModel.DATA_TYPES;
|
|
389
|
+
this._changed();
|
|
390
|
+
this._redraw();
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
removeDataType(id) {
|
|
395
|
+
this.model.removeDataType(id);
|
|
396
|
+
if (this.level === DataModel.DATA_TYPES && !this.model.dataTypes.length) this.chartOptions.level = 'logical';
|
|
397
|
+
this._changed();
|
|
398
|
+
this._redraw();
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/** Check the model (DataModelChecker) and list the findings; choosing one shows it (revealFinding). Returns the findings. */
|
|
402
|
+
checkModel() {
|
|
403
|
+
const findings = this.model.checker().run();
|
|
404
|
+
new ModelCheckDialog({ findings, onReveal: (finding) => this.revealFinding(finding), document: this.document }).open();
|
|
405
|
+
return findings;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/** Show what a finding names: an entity's level, a service domain seen through at the logical level, the mapping or data types view. */
|
|
409
|
+
revealFinding(finding) {
|
|
410
|
+
if (finding.kind === 'perspective') {
|
|
411
|
+
this.chartOptions.level = 'logical';
|
|
412
|
+
this.setPerspective(finding.ids[0]);
|
|
413
|
+
} else if (finding.kind === 'mapping') {
|
|
414
|
+
this.setLevel(DataModel.MAPPING);
|
|
415
|
+
} else if (finding.kind === 'data-type') {
|
|
416
|
+
this.setLevel(DataModel.DATA_TYPES);
|
|
417
|
+
} else if (finding.level) {
|
|
418
|
+
this.setLevel(finding.level);
|
|
419
|
+
}
|
|
420
|
+
this.menuBar?.render?.();
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/** A dialog making a perspective (none given) or changing one (DataModelPerspective.fields); applied, it is the one seen through. */
|
|
424
|
+
editPerspective(perspective, Kind = perspective?.constructor ?? DataModelPerspective) {
|
|
425
|
+
const title = perspective ? `${Kind.kindLabel}: ${perspective.name}` : `New ${Kind.kindLabel.toLowerCase()}`;
|
|
426
|
+
return this._dialog(title, Kind.fields(this.model, perspective), (values) => {
|
|
427
|
+
const spec = Kind.specFrom(values, this.model, perspective);
|
|
428
|
+
const saved = perspective ? this.model.updatePerspective(perspective.id, spec) : this.model.addPerspective(spec);
|
|
429
|
+
this._changed();
|
|
430
|
+
this.setPerspective(saved.id);
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** A dialog making a context (none given) or changing one (DataModelContext.fields); applied, it is the one read in. */
|
|
435
|
+
editContext(context) {
|
|
436
|
+
return this._dialog(context ? `Context: ${context.name}` : 'New context', DataModelContext.fields(this.model, context), (values) => {
|
|
437
|
+
const spec = DataModelContext.specFrom(values, this.model, context);
|
|
438
|
+
const saved = context ? this.model.updateContext(context.id, spec) : this.model.addContext(spec);
|
|
439
|
+
this._changed();
|
|
440
|
+
this.setContext(saved.id);
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
removePerspective(id) {
|
|
445
|
+
this.model.removePerspective(id);
|
|
446
|
+
this._changed();
|
|
447
|
+
this.setPerspective(null);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
removeContext(id) {
|
|
451
|
+
this.model.removeContext(id);
|
|
452
|
+
this._changed();
|
|
453
|
+
this.setContext(null);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** Open a form (a name is needed). @private */
|
|
457
|
+
_dialog(title, fields, apply) {
|
|
458
|
+
return new FormDialog({
|
|
459
|
+
title, fields, submitLabel: 'Save', idPrefix: 'data-model-',
|
|
460
|
+
document: this.container?.ownerDocument ?? globalThis.document,
|
|
461
|
+
validate: ({ name }) => ((name ?? '').trim() ? null : 'Give it a name'),
|
|
462
|
+
onApply: apply,
|
|
463
|
+
}).open();
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
/** The perspectives or contexts changed: the toolbar shows them anew. @private */
|
|
467
|
+
_changed() {
|
|
468
|
+
if (this.menuBar) this.menuBar.items = this.menuBarItems();
|
|
469
|
+
this.menuBar?.render?.();
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/** Export ▸: the picture, as PNG or SVG, named after the model. */
|
|
473
|
+
exportItems() {
|
|
474
|
+
const name = this.model.name || this.title || 'data-model';
|
|
475
|
+
return [
|
|
476
|
+
{ label: 'Image (PNG)', action: () => downloadPng(this.canvasHost, { name }) },
|
|
477
|
+
{ label: 'Image (SVG)', action: () => downloadSvg(this.canvasHost, { name }) },
|
|
478
|
+
];
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/** Redraw now (a choice made), when there is somewhere to draw. @private */
|
|
482
|
+
_redraw() {
|
|
483
|
+
if (this.canvasHost) this._draw();
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Keep where the boxes and notes were dragged (the drawing is made anew each
|
|
488
|
+
* time): on the level shown, or in the mapping view's own layout. Then draw.
|
|
489
|
+
*/
|
|
490
|
+
_draw() {
|
|
491
|
+
if (this._keepPlaces()) this.model.edited(); // a box or note moved is a change, kept and saved
|
|
492
|
+
this._drawnLevel = this.level;
|
|
493
|
+
super._draw();
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
/**
|
|
497
|
+
* Keep where the drawing on screen has its boxes and notes: on the level
|
|
498
|
+
* it shows, or in the mapping view's layout. Returns whether any moved. @private
|
|
499
|
+
*/
|
|
500
|
+
_keepPlaces() {
|
|
501
|
+
const pos = this.engine?._graph?.pos;
|
|
502
|
+
if (!pos || !this._drawnLevel) return false;
|
|
503
|
+
let moved = false;
|
|
504
|
+
const place = (p, before, put) => {
|
|
505
|
+
if (!p || (before && before.x === p.x && before.y === p.y)) return;
|
|
506
|
+
put({ x: p.x, y: p.y });
|
|
507
|
+
moved = true;
|
|
508
|
+
};
|
|
509
|
+
const other = DataModel.otherView(this._drawnLevel);
|
|
510
|
+
if (other && !other.keepsPlaces) return false; // laid out by its structure, anew each time
|
|
511
|
+
if (other) {
|
|
512
|
+
for (const [id, p] of pos) {
|
|
513
|
+
if (id.includes(':')) place(p, this.model.mappingLayout[id], (at) => { this.model.mappingLayout[id] = at; });
|
|
514
|
+
}
|
|
515
|
+
return moved;
|
|
516
|
+
}
|
|
517
|
+
for (const entity of this.model.level(this._drawnLevel).entities) {
|
|
518
|
+
place(pos.get(entity.id), entity, (at) => Object.assign(entity, at));
|
|
519
|
+
}
|
|
520
|
+
for (const rule of this.model.contexts.flatMap(c => c.constraints)) {
|
|
521
|
+
const p = pos.get(rule.id);
|
|
522
|
+
const before = this.model.notePlace(this._drawnLevel, rule);
|
|
523
|
+
place(p, Number.isFinite(before.x) ? before : null, (at) => this.model.placeNote(this._drawnLevel, rule, at));
|
|
524
|
+
}
|
|
525
|
+
return moved;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
dispose() {
|
|
529
|
+
this._unsubscribeEdits?.();
|
|
530
|
+
this.file.restoreTitle();
|
|
531
|
+
this.menuBar?.dispose?.();
|
|
532
|
+
super.dispose();
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/** The spec again: the model (with where its boxes are), what is chosen, and the other options. */
|
|
536
|
+
serialize() {
|
|
537
|
+
const { options, chartType, ...base } = super.serialize();
|
|
538
|
+
const { level, notation, ...rest } = options;
|
|
539
|
+
return {
|
|
540
|
+
...base, ...this.model.toJSON(),
|
|
541
|
+
perspective: this.perspectiveId, context: this.contextId, level, notation, options: rest,
|
|
542
|
+
};
|
|
543
|
+
}
|
|
544
|
+
}
|
|
@@ -4,7 +4,6 @@ import { EditorPart } from './EditorPart.js';
|
|
|
4
4
|
import { DiagramEditor } from '../../charting/DiagramEditor.js';
|
|
5
5
|
import { MenuBar } from '../../charting/MenuBar.js';
|
|
6
6
|
import { DiagramModel } from '../../charting/diagramModel/index.js';
|
|
7
|
-
import { ViewTabStrip } from '../../charting/ViewTabStrip.js';
|
|
8
7
|
import { LocalJsonStore } from '../../charting/storage/LocalJsonStore.js';
|
|
9
8
|
import { EdgeStyleCascade } from '../../charting/edgeStyle/index.js';
|
|
10
9
|
import { DiagramViewPropertiesDialog } from '../../charting/DiagramViewPropertiesDialog.js';
|
|
@@ -64,15 +63,10 @@ export class DiagramEditorPart extends EditorPart {
|
|
|
64
63
|
elements.id = 'elements';
|
|
65
64
|
canvas.appendChild(elements);
|
|
66
65
|
|
|
67
|
-
const tabs =
|
|
68
|
-
orientation: this.tabOrientation,
|
|
69
|
-
document: doc,
|
|
70
|
-
onSelect: (id) => model.switchTo(id),
|
|
71
|
-
menuItems: (id) => this.viewMenu.items(id),
|
|
72
|
-
}).render(model.views(), model.currentViewId);
|
|
66
|
+
const tabs = this.viewTabs({ orientation: this.tabOrientation });
|
|
73
67
|
|
|
74
68
|
// The shared workbench layout: toolbar, palette at the side, tabs + canvas in the main area.
|
|
75
|
-
const { toolbar: menuBarEl, side: palette, main } = new EditorShell({ document: doc, sideWidth: '200px' }).mount(this.container);
|
|
69
|
+
const { toolbar: menuBarEl, side: palette, main } = new EditorShell({ document: doc, sideWidth: '200px', layout: this.layout, labels: { side: 'Palette' } }).mount(this.container);
|
|
76
70
|
palette.classList.add('ws-diagram-palette');
|
|
77
71
|
Object.assign(palette.style, { padding: '8px', fontSize: '12px', display: 'flex', flexDirection: 'column', overflowY: 'hidden' });
|
|
78
72
|
main.style.flexDirection = this.tabOrientation === 'vertical' ? 'row' : 'column';
|