Updates dmn-js so we can remove redundant importXML code

This commit is contained in:
Aaron Louie 2021-08-13 17:47:04 -04:00
parent 97e020ea9a
commit 35cd8f767f
5 changed files with 95 additions and 140 deletions

136
package-lock.json generated
View File

@ -30,8 +30,9 @@
"diagram-js": "^7.3.0",
"diagram-js-code-editor": "^1.1.8",
"diagram-js-minimap": "^2.0.4",
"dmn-js": "10.3.0",
"dmn-js": "^11.0.1",
"dmn-js-properties-panel": "^0.6.1",
"dmn-js-shared": "^11.0.0",
"dmn-moddle": "^10.0.0",
"file-saver": "^2.0.5",
"fs-extra": "^10.0.0",
@ -82,6 +83,7 @@
"karma-jasmine-html-reporter": "^1.7.0",
"lodash.isequal": "^4.5.0",
"mockdate": "^3.0.5",
"moddle-xml": "^9.0.5",
"postcss-loader": "^6.1.1",
"postcss-short": "^5.0.0",
"puppeteer": "^10.2.0",
@ -6870,24 +6872,24 @@
}
},
"node_modules/dmn-js": {
"version": "10.3.0",
"resolved": "https://registry.npmjs.org/dmn-js/-/dmn-js-10.3.0.tgz",
"integrity": "sha512-miJOLOrs9i8jvE7tutjEbpUn8fWmdb7xiAAKlyeRcSefLlBpwiIFmC0V7pbqPaB9D2fVN6vI8SP7TvRmif+CMw==",
"version": "11.0.1",
"resolved": "https://registry.npmjs.org/dmn-js/-/dmn-js-11.0.1.tgz",
"integrity": "sha512-7vXID2fpmPt27Ssy/X7q/BO1IEgdb5B8iq8z/OOEXjkCOqlhBckPMJC2ysKHZuOod1mXA4N2Y1URZ7CU9F3xFg==",
"dependencies": {
"dmn-js-decision-table": "^10.3.0",
"dmn-js-drd": "^10.3.0",
"dmn-js-literal-expression": "^10.3.0",
"dmn-js-shared": "^10.3.0"
"dmn-js-decision-table": "^11.0.1",
"dmn-js-drd": "^11.0.1",
"dmn-js-literal-expression": "^11.0.1",
"dmn-js-shared": "^11.0.0"
}
},
"node_modules/dmn-js-decision-table": {
"version": "10.3.0",
"resolved": "https://registry.npmjs.org/dmn-js-decision-table/-/dmn-js-decision-table-10.3.0.tgz",
"integrity": "sha512-H9QXjNT6FH6QuSXytCAaK5/qRT/3QAkwnc0RzhAjo+lqmIeDK2bOgvY8SSVHCm1xT3RzTzepJLRLBg9G+Jg7Dw==",
"version": "11.0.1",
"resolved": "https://registry.npmjs.org/dmn-js-decision-table/-/dmn-js-decision-table-11.0.1.tgz",
"integrity": "sha512-STqGpbClwd7keXIFwsVZD2GJehAV9RH2Vc2gLeSCjxAeVpWdSzi5BNTRjeMpr5SusWO4ORR+rPT5Ahx94xj8vQ==",
"dependencies": {
"css.escape": "^1.5.1",
"diagram-js": "^7.2.0",
"dmn-js-shared": "^10.3.0",
"dmn-js-shared": "^11.0.0",
"escape-html": "^1.0.3",
"inferno": "~5.6.2",
"min-dash": "^3.5.2",
@ -6897,13 +6899,13 @@
}
},
"node_modules/dmn-js-drd": {
"version": "10.3.0",
"resolved": "https://registry.npmjs.org/dmn-js-drd/-/dmn-js-drd-10.3.0.tgz",
"integrity": "sha512-GF7SsjBs945VbexyxsyzZaJrZ86Te5HwSPXQKIrYZOol+SszYG2VfN4tSBjb0rUhqrQYMG+S1t1VxLUMNxqfig==",
"version": "11.0.1",
"resolved": "https://registry.npmjs.org/dmn-js-drd/-/dmn-js-drd-11.0.1.tgz",
"integrity": "sha512-RvjVT+QbN7q4UzAQnqYH4/SWNcLvvKN6UJmWPaYiWpmN29HXAWN6jn9GolcN635JMM2satlcRIU7SmQmfopapA==",
"dependencies": {
"diagram-js": "^7.2.0",
"diagram-js-direct-editing": "^1.6.3",
"dmn-js-shared": "^10.3.0",
"dmn-js-shared": "^11.0.0",
"inherits": "^2.0.1",
"min-dash": "^3.5.2",
"min-dom": "^3.1.3",
@ -6912,12 +6914,12 @@
}
},
"node_modules/dmn-js-literal-expression": {
"version": "10.3.0",
"resolved": "https://registry.npmjs.org/dmn-js-literal-expression/-/dmn-js-literal-expression-10.3.0.tgz",
"integrity": "sha512-CsZ2su6dAmSVqFrBfEAC5HvbnT6GZ7j1Dy88TYBZ3Ak4Bpz2z0k9wE1BSUBMX1ck9N1V6stuha8NKHFwq4ZjoQ==",
"version": "11.0.1",
"resolved": "https://registry.npmjs.org/dmn-js-literal-expression/-/dmn-js-literal-expression-11.0.1.tgz",
"integrity": "sha512-Q5edmkTZNGSyCf07CkzObJDd1byxr7LjzJN50kUV516JUBpnw3yIfc6N3SP44oU32wLJbmQ/UpmIcV9Opst6nA==",
"dependencies": {
"diagram-js": "^7.2.0",
"dmn-js-shared": "^10.3.0",
"dmn-js-shared": "^11.0.0",
"escape-html": "^1.0.3",
"inferno": "~5.6.2",
"min-dash": "^3.5.2",
@ -6942,13 +6944,13 @@
}
},
"node_modules/dmn-js-shared": {
"version": "10.3.0",
"resolved": "https://registry.npmjs.org/dmn-js-shared/-/dmn-js-shared-10.3.0.tgz",
"integrity": "sha512-m+Uk7STxrJPVkhdkiBYZJJKTknZXzwGW+ieECrquXorV2XEgPkYJesCkQyDQrp6q3qCe0z7Lbg1u40S7NYZIlw==",
"version": "11.0.0",
"resolved": "https://registry.npmjs.org/dmn-js-shared/-/dmn-js-shared-11.0.0.tgz",
"integrity": "sha512-aNTbzclBMWHu6EhkdjFcowMuzBd40wt2WHo9WGKl88H3lYH5QLC2aMBNxOOqroYEkcWcTeZbOrSWNnn+0zORbQ==",
"dependencies": {
"camunda-dmn-moddle": "^1.0.0",
"diagram-js": "^7.2.0",
"dmn-moddle": "^9.1.0",
"dmn-moddle": "^10.0.0",
"ids": "^0.2.0",
"inferno": "~5.6.2",
"min-dash": "^3.5.2",
@ -6958,16 +6960,6 @@
"table-js": "^7.1.0"
}
},
"node_modules/dmn-js-shared/node_modules/dmn-moddle": {
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/dmn-moddle/-/dmn-moddle-9.1.0.tgz",
"integrity": "sha512-LA76wn5SD5fjExD0ZqHAngApN6iGb2bQhKFZCykQa6uyTadBys4kmgcv/sYv/WAm5cY0DcS/Vnn35YgK75f6VQ==",
"dependencies": {
"min-dash": "^3.0.0",
"moddle": "^5.0.1",
"moddle-xml": "^8.0.1"
}
},
"node_modules/dmn-js-shared/node_modules/ids": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/ids/-/ids-0.2.2.tgz",
@ -6976,16 +6968,6 @@
"hat": "^0.0.3"
}
},
"node_modules/dmn-js-shared/node_modules/moddle-xml": {
"version": "8.0.8",
"resolved": "https://registry.npmjs.org/moddle-xml/-/moddle-xml-8.0.8.tgz",
"integrity": "sha512-JzW8wUCH7Qze7eh0T8A1exi7QJg6hRgq+uw8goHNP5Q7pWTGrLj83S+NgA/94M2I0JmqnK9hw3sCbyiKVOjc4Q==",
"dependencies": {
"min-dash": "^3.0.0",
"moddle": "^5.0.1",
"saxen": "^8.1.2"
}
},
"node_modules/dmn-moddle": {
"version": "10.0.0",
"resolved": "https://registry.npmjs.org/dmn-moddle/-/dmn-moddle-10.0.0.tgz",
@ -26457,24 +26439,24 @@
}
},
"dmn-js": {
"version": "10.3.0",
"resolved": "https://registry.npmjs.org/dmn-js/-/dmn-js-10.3.0.tgz",
"integrity": "sha512-miJOLOrs9i8jvE7tutjEbpUn8fWmdb7xiAAKlyeRcSefLlBpwiIFmC0V7pbqPaB9D2fVN6vI8SP7TvRmif+CMw==",
"version": "11.0.1",
"resolved": "https://registry.npmjs.org/dmn-js/-/dmn-js-11.0.1.tgz",
"integrity": "sha512-7vXID2fpmPt27Ssy/X7q/BO1IEgdb5B8iq8z/OOEXjkCOqlhBckPMJC2ysKHZuOod1mXA4N2Y1URZ7CU9F3xFg==",
"requires": {
"dmn-js-decision-table": "^10.3.0",
"dmn-js-drd": "^10.3.0",
"dmn-js-literal-expression": "^10.3.0",
"dmn-js-shared": "^10.3.0"
"dmn-js-decision-table": "^11.0.1",
"dmn-js-drd": "^11.0.1",
"dmn-js-literal-expression": "^11.0.1",
"dmn-js-shared": "^11.0.0"
}
},
"dmn-js-decision-table": {
"version": "10.3.0",
"resolved": "https://registry.npmjs.org/dmn-js-decision-table/-/dmn-js-decision-table-10.3.0.tgz",
"integrity": "sha512-H9QXjNT6FH6QuSXytCAaK5/qRT/3QAkwnc0RzhAjo+lqmIeDK2bOgvY8SSVHCm1xT3RzTzepJLRLBg9G+Jg7Dw==",
"version": "11.0.1",
"resolved": "https://registry.npmjs.org/dmn-js-decision-table/-/dmn-js-decision-table-11.0.1.tgz",
"integrity": "sha512-STqGpbClwd7keXIFwsVZD2GJehAV9RH2Vc2gLeSCjxAeVpWdSzi5BNTRjeMpr5SusWO4ORR+rPT5Ahx94xj8vQ==",
"requires": {
"css.escape": "^1.5.1",
"diagram-js": "^7.2.0",
"dmn-js-shared": "^10.3.0",
"dmn-js-shared": "^11.0.0",
"escape-html": "^1.0.3",
"inferno": "~5.6.2",
"min-dash": "^3.5.2",
@ -26484,13 +26466,13 @@
}
},
"dmn-js-drd": {
"version": "10.3.0",
"resolved": "https://registry.npmjs.org/dmn-js-drd/-/dmn-js-drd-10.3.0.tgz",
"integrity": "sha512-GF7SsjBs945VbexyxsyzZaJrZ86Te5HwSPXQKIrYZOol+SszYG2VfN4tSBjb0rUhqrQYMG+S1t1VxLUMNxqfig==",
"version": "11.0.1",
"resolved": "https://registry.npmjs.org/dmn-js-drd/-/dmn-js-drd-11.0.1.tgz",
"integrity": "sha512-RvjVT+QbN7q4UzAQnqYH4/SWNcLvvKN6UJmWPaYiWpmN29HXAWN6jn9GolcN635JMM2satlcRIU7SmQmfopapA==",
"requires": {
"diagram-js": "^7.2.0",
"diagram-js-direct-editing": "^1.6.3",
"dmn-js-shared": "^10.3.0",
"dmn-js-shared": "^11.0.0",
"inherits": "^2.0.1",
"min-dash": "^3.5.2",
"min-dom": "^3.1.3",
@ -26499,12 +26481,12 @@
}
},
"dmn-js-literal-expression": {
"version": "10.3.0",
"resolved": "https://registry.npmjs.org/dmn-js-literal-expression/-/dmn-js-literal-expression-10.3.0.tgz",
"integrity": "sha512-CsZ2su6dAmSVqFrBfEAC5HvbnT6GZ7j1Dy88TYBZ3Ak4Bpz2z0k9wE1BSUBMX1ck9N1V6stuha8NKHFwq4ZjoQ==",
"version": "11.0.1",
"resolved": "https://registry.npmjs.org/dmn-js-literal-expression/-/dmn-js-literal-expression-11.0.1.tgz",
"integrity": "sha512-Q5edmkTZNGSyCf07CkzObJDd1byxr7LjzJN50kUV516JUBpnw3yIfc6N3SP44oU32wLJbmQ/UpmIcV9Opst6nA==",
"requires": {
"diagram-js": "^7.2.0",
"dmn-js-shared": "^10.3.0",
"dmn-js-shared": "^11.0.0",
"escape-html": "^1.0.3",
"inferno": "~5.6.2",
"min-dash": "^3.5.2",
@ -26526,13 +26508,13 @@
}
},
"dmn-js-shared": {
"version": "10.3.0",
"resolved": "https://registry.npmjs.org/dmn-js-shared/-/dmn-js-shared-10.3.0.tgz",
"integrity": "sha512-m+Uk7STxrJPVkhdkiBYZJJKTknZXzwGW+ieECrquXorV2XEgPkYJesCkQyDQrp6q3qCe0z7Lbg1u40S7NYZIlw==",
"version": "11.0.0",
"resolved": "https://registry.npmjs.org/dmn-js-shared/-/dmn-js-shared-11.0.0.tgz",
"integrity": "sha512-aNTbzclBMWHu6EhkdjFcowMuzBd40wt2WHo9WGKl88H3lYH5QLC2aMBNxOOqroYEkcWcTeZbOrSWNnn+0zORbQ==",
"requires": {
"camunda-dmn-moddle": "^1.0.0",
"diagram-js": "^7.2.0",
"dmn-moddle": "^9.1.0",
"dmn-moddle": "^10.0.0",
"ids": "^0.2.0",
"inferno": "~5.6.2",
"min-dash": "^3.5.2",
@ -26542,16 +26524,6 @@
"table-js": "^7.1.0"
},
"dependencies": {
"dmn-moddle": {
"version": "9.1.0",
"resolved": "https://registry.npmjs.org/dmn-moddle/-/dmn-moddle-9.1.0.tgz",
"integrity": "sha512-LA76wn5SD5fjExD0ZqHAngApN6iGb2bQhKFZCykQa6uyTadBys4kmgcv/sYv/WAm5cY0DcS/Vnn35YgK75f6VQ==",
"requires": {
"min-dash": "^3.0.0",
"moddle": "^5.0.1",
"moddle-xml": "^8.0.1"
}
},
"ids": {
"version": "0.2.2",
"resolved": "https://registry.npmjs.org/ids/-/ids-0.2.2.tgz",
@ -26559,16 +26531,6 @@
"requires": {
"hat": "^0.0.3"
}
},
"moddle-xml": {
"version": "8.0.8",
"resolved": "https://registry.npmjs.org/moddle-xml/-/moddle-xml-8.0.8.tgz",
"integrity": "sha512-JzW8wUCH7Qze7eh0T8A1exi7QJg6hRgq+uw8goHNP5Q7pWTGrLj83S+NgA/94M2I0JmqnK9hw3sCbyiKVOjc4Q==",
"requires": {
"min-dash": "^3.0.0",
"moddle": "^5.0.1",
"saxen": "^8.1.2"
}
}
}
},

View File

@ -48,8 +48,9 @@
"diagram-js": "^7.3.0",
"diagram-js-code-editor": "^1.1.8",
"diagram-js-minimap": "^2.0.4",
"dmn-js": "10.3.0",
"dmn-js": "^11.0.1",
"dmn-js-properties-panel": "^0.6.1",
"dmn-js-shared": "^11.0.0",
"dmn-moddle": "^10.0.0",
"file-saver": "^2.0.5",
"fs-extra": "^10.0.0",
@ -100,6 +101,7 @@
"karma-jasmine-html-reporter": "^1.7.0",
"lodash.isequal": "^4.5.0",
"mockdate": "^3.0.5",
"moddle-xml": "^9.0.5",
"postcss-loader": "^6.1.1",
"postcss-short": "^5.0.0",
"puppeteer": "^10.2.0",

View File

@ -16,7 +16,7 @@ import {
import {
BPMN_DIAGRAM,
BPMN_DIAGRAM_WITH_WARNINGS,
DMN_DIAGRAM,
DMN_DIAGRAM, DMN_DIAGRAM_EMPTY,
DMN_DIAGRAM_WITH_WARNINGS,
} from '../../testing/mocks/diagram.mocks';
import { DiagramComponent } from './diagram.component';
@ -121,9 +121,9 @@ describe('DiagramComponent', () => {
it('should expose DMN import warnings', (done) => {
const diagramURL = 'some-url';
component.importDone.subscribe(result => {
expect(result.type).toEqual('success');
expect(result.warnings.length).toEqual(1);
expect(result.warnings[0].message).toContain('unparsable content <decision> detected');
expect(result.type).toEqual('error');
expect(result.error.warnings.length).toEqual(1);
expect(result.error.warnings[0].message).toContain('unparsable content <decision> detected');
done();
});
component.loadUrl(diagramURL);
@ -192,10 +192,10 @@ describe('DiagramComponent', () => {
expect(importXMLSpy).toHaveBeenCalled();
});
it('should open an existing DMN diagram from XML', () => {
it('should open an existing DMN diagram from XML', async () => {
const initializeDMNModelerSpy = spyOn(component, 'initializeDMNModeler').and.stub();
const importXMLSpy = spyOn(component.modeler, 'importXML').and.callThrough();
component.openDiagram(DMN_DIAGRAM, FileType.DMN);
await component.openDiagram(DMN_DIAGRAM, FileType.DMN);
expect(initializeDMNModelerSpy).toHaveBeenCalled();
expect(importXMLSpy).toHaveBeenCalled();
});
@ -239,16 +239,20 @@ describe('DiagramComponent', () => {
expect(onChangeSpy).toHaveBeenCalled();
});
it('should edit DMN diagram', () => {
it('should edit DMN diagram', async () => {
fixture.detectChanges();
await fixture.whenRenderingDone();
const initializeModelerSpy = spyOn(component, 'initializeModeler').and.stub();
const onChangeSpy = spyOn(component, 'onChange').and.stub();
const dmnMigrateSpy = spyOn((component as any), 'convertDMN').and.returnValue(DMN_DIAGRAM_EMPTY);
const importXMLSpy = spyOn(component.modeler, 'importXML').and.callThrough();
spyOn(component, 'getRandomString').and.returnValue('REPLACE_ME');
component.diagramType = FileType.DMN;
component.openDiagram(DMN_DIAGRAM_DEFAULT, FileType.DMN);
await component.openDiagram(DMN_DIAGRAM_DEFAULT, FileType.DMN);
expect(initializeModelerSpy).toHaveBeenCalledWith(FileType.DMN);
expect(importXMLSpy).toHaveBeenCalledWith(DMN_DIAGRAM_DEFAULT, jasmine.any(Function));
expect(dmnMigrateSpy).toHaveBeenCalledOnceWith(DMN_DIAGRAM_DEFAULT);
expect(importXMLSpy).toHaveBeenCalledWith(DMN_DIAGRAM_EMPTY);
initializeModelerSpy.calls.reset();
component.writeValue(DMN_DIAGRAM);

View File

@ -139,11 +139,7 @@ export class DiagramComponent implements ControlValueAccessor, AfterViewInit, On
}
openDiagram(xml?: string, diagramType?: FileType) {
console.log('openDiagram > diagramType', diagramType);
this.diagramType = diagramType || getDiagramTypeFromXml(xml);
console.log('openDiagram > this.diagramType', this.diagramType);
this.xml = xml;
const modeler = this.initializeModeler(diagramType);
@ -156,19 +152,12 @@ export class DiagramComponent implements ControlValueAccessor, AfterViewInit, On
xml = defaultXml.replace(/REPLACE_ME/gi, () => randomString);
}
// Add an arbitrary string to get the save button to enable
if (isDMN) {
// DMN Modeler takes a callback
// Convert any v1.1 or 1.2 DMN files to v1.3
const convertedXML = await this.convertDMN(xml);
this.modeler.importXML(convertedXML, (e, w) => this.onImport(e, w || e && e.warnings));
} else {
// BPMN Modeler returns a Promise
this.modeler.importXML(xml).then(
(e, w) => this.onImport(e, w || e && e.warnings),
e => this.onImport(e, e && e.warnings),
);
}
// Convert any DMN 1.1 or 1.2 DMN to v1.3
const convertedXML = isDMN ? await this.convertDMN(xml) : xml;
this.modeler.importXML(convertedXML).then(
(e, w) => this.onImport(e, w || e && e.warnings),
e => this.onImport(e, e && e.warnings),
);
});
}
@ -274,6 +263,7 @@ export class DiagramComponent implements ControlValueAccessor, AfterViewInit, On
}
private initializeBPMNModeler(): BpmnModeler {
this.diagramType = FileType.BPMN;
this.modeler = new BpmnModeler({
container: this.containerRef.nativeElement,
propertiesPanel: {
@ -315,6 +305,7 @@ export class DiagramComponent implements ControlValueAccessor, AfterViewInit, On
private initializeDMNModeler(): DmnModeler {
this.diagramType = FileType.DMN;
this.modeler = new DmnModeler({
container: this.containerRef.nativeElement,
drd: {

View File

@ -46,31 +46,27 @@ export const BPMN_DIAGRAM_WITH_WARNINGS = `
</definitions>
`;
export const DMN_DIAGRAM_EMPTY = `
<?xml version="1.0" encoding="UTF-8"?>
<definitions
xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/"
xmlns:dmndi="https://www.omg.org/spec/DMN/20191111/DMNDI/"
xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/"
>
<decision id="Decision_REPLACE_ME" name="Decision_REPLACE_ME">
<decisionTable id="decisionTable_1">
<input id="input_1">
<inputExpression id="inputExpression_1" typeRef="string">
<text></text>
</inputExpression>
</input>
<output id="output_1" typeRef="string" />
</decisionTable>
</decision>
<dmndi:DMNDI>
<dmndi:DMNDiagram id="DMNDiagram_REPLACE_ME">
<dmndi:DMNShape id="DMNShape_REPLACE_ME" dmnElementRef="Decision_REPLACE_ME">
<dc:Bounds height="80" width="180" x="100" y="100" />
</dmndi:DMNShape>
</dmndi:DMNDiagram>
</dmndi:DMNDI>
</definitions>
export const DMN_DIAGRAM_EMPTY = '<?xml version="1.0" encoding="UTF-8"?>\n' +
// eslint-disable-next-line max-len
`<definitions xmlns="https://www.omg.org/spec/DMN/20191111/MODEL/" xmlns:dmndi="https://www.omg.org/spec/DMN/20191111/DMNDI/" xmlns:dc="http://www.omg.org/spec/DMN/20180521/DC/" id="Definitions_REPLACE_ME" name="DRD" namespace="http://camunda.org/schema/1.0/dmn">
<decision id="Decision_REPLACE_ME" name="Decision 1">
<decisionTable id="decisionTable_1">
<input id="input_1">
<inputExpression id="inputExpression_1" typeRef="string">
<text></text>
</inputExpression>
</input>
<output id="output_1" typeRef="string" />
</decisionTable>
</decision>
<dmndi:DMNDI>
<dmndi:DMNDiagram id="DMNDiagram_1f4cl4k">
<dmndi:DMNShape id="DMNShape_0yvbgg8" dmnElementRef="Decision_REPLACE_ME">
<dc:Bounds height="80" width="180" x="157" y="81" />
</dmndi:DMNShape>
</dmndi:DMNDiagram>
</dmndi:DMNDI>
</definitions>
`;
export const DMN_DIAGRAM = `