Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: migrate the code of the demo/test pages to TypeScript #2794

Merged
merged 33 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6d9c4d2
START move bpmn-rendering.js
tbouffard Aug 17, 2023
3ee7b24
move main.ts
tbouffard Aug 17, 2023
bf3760b
move internal-helpers.ts
tbouffard Aug 17, 2023
12e857f
Revert "move internal-helpers.ts"
tbouffard Aug 17, 2023
48906a4
rename utils into shared
tbouffard Aug 17, 2023
bd9c031
convert bpmn-rendering.js to TS
tbouffard Aug 17, 2023
d2a286f
move index.js
tbouffard Aug 17, 2023
beaa116
index.js: fix import
tbouffard Aug 17, 2023
3acfdac
vite config: mxgraph warning limit increase
tbouffard Aug 17, 2023
8f46394
move elements-identification.js
tbouffard Aug 17, 2023
663e658
move lib-integration.js
tbouffard Aug 17, 2023
424063f
lib-integration.js: fix import
tbouffard Aug 17, 2023
014afa5
lib-integration.js: move to TS
tbouffard Aug 17, 2023
43f38e8
move overlays.js
tbouffard Aug 17, 2023
4b3fa1b
move diagram-navigation.js
tbouffard Aug 17, 2023
192497f
WIP move controls.js
tbouffard Aug 17, 2023
c09d255
WIP move controls.js to TS
tbouffard Aug 17, 2023
f2cb503
WIP move controls.js to TS
tbouffard Aug 17, 2023
e12b7d8
bpmn-rendering.html: fix TS file loading
tbouffard Aug 17, 2023
dfaf0c2
migrate overlays.js to TS
tbouffard Aug 17, 2023
973e7c6
diagram-navigation.ts to TS
tbouffard Aug 17, 2023
30b5f24
WIP migrate elements-identification.js to TS
tbouffard Aug 17, 2023
3f04ecc
WIP migrate index.js to TS
tbouffard Aug 17, 2023
9624d28
bpmn-rendering.ts: restore function declaration
tbouffard Aug 17, 2023
cb8afbe
WIP fix TS error
tbouffard Aug 17, 2023
45e3615
WIP fix TS error
tbouffard Aug 17, 2023
f34787f
WIP fix TS error
tbouffard Aug 17, 2023
07e3a96
WIP fix TS error
tbouffard Aug 17, 2023
12ccd26
WIP fix TS error
tbouffard Aug 17, 2023
d06c0c6
extra utils code from mxgraph/renderer to reuse in the demo
tbouffard Aug 17, 2023
077dbe0
style-utils.ts: restore original style/identifiers import
tbouffard Aug 17, 2023
84d028a
index.ts: restore function parameter name
tbouffard Aug 17, 2023
78095e4
controls.ts: remove usage of ts-ignore
tbouffard Aug 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/public/bpmn-rendering.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
font-weight: bold;
}
</style>
<script src="./static/js/bpmn-rendering.js" type="module"></script>
<script src="../ts/pages/bpmn-rendering.ts" type="module"></script>
</head>
<body>
<div id="status-zone"></div>
Expand Down
2 changes: 1 addition & 1 deletion dev/public/diagram-navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
width: 35px;
}
</style>
<script src="./static/js/diagram-navigation.js" type="module"></script>
<script src="../ts/pages/diagram-navigation.ts" type="module"></script>
</head>
<body>
<div class="flex-container">
Expand Down
2 changes: 1 addition & 1 deletion dev/public/elements-identification.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
color: var(--color-flow) !important;
}
</style>
<script src="./static/js/elements-identification.js" type="module"></script>
<script src="../ts/pages/elements-identification.ts" type="module"></script>
</head>
<body>
<div id="controls">
Expand Down
2 changes: 1 addition & 1 deletion dev/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v6.4.2/css/all.css">
<link href="./static/css/styles.css" rel="stylesheet">
<link rel="icon" type="image/svg+xml" href="./static/img/favicon.svg">
<script src="./static/js/index.js" type="module"></script>
<script src="../ts/pages/index.ts" type="module"></script>
</head>
<body class="bg-gray-800 font-sans leading-normal tracking-normal flex flex-col h-screen">
<!--Nav-->
Expand Down
2 changes: 1 addition & 1 deletion dev/public/lib-integration.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="UTF-8">
<title>bpmn-visualization - Library Integration</title>
<link rel="icon" type="image/svg+xml" href="./static/img/favicon.svg">
<script src="./static/js/lib-integration.js" type="module"></script>
<script src="../ts/pages/lib-integration.ts" type="module"></script>
</head>
<body>
<div id="bpmn-container-custom"></div>
Expand Down
2 changes: 1 addition & 1 deletion dev/public/overlays.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
background-color: MintCream;
}
</style>
<script src="./static/js/overlays.js" type="module"></script>
<script src="../ts/pages/overlays.ts" type="module"></script>
</head>
<body>
<div class="flex-container">
Expand Down
2 changes: 1 addition & 1 deletion dev/ts/component/DropFileUserInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { logErrorAndOpenAlert } from '../utils/internal-helpers';
import { logErrorAndOpenAlert } from '../shared/internal-helpers';

export class DropFileUserInterface {
private document: Document;
Expand Down
2 changes: 1 addition & 1 deletion dev/ts/component/ThemedBpmnVisualization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/

import { BpmnVisualization, FlowKind, ShapeBpmnElementKind, ShapeUtil, StyleConfigurator, StyleDefault } from '../../../src/bpmn-visualization';
import { logStartup } from '../utils/internal-helpers';
import { logStartup } from '../shared/internal-helpers';
import { mxConstants } from '../../../src/component/mxgraph/initializer';

interface Theme {
Expand Down
2 changes: 1 addition & 1 deletion dev/ts/component/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { logDownload } from '../utils/internal-helpers';
import { logDownload } from '../shared/internal-helpers';

// inspired from https://ourcodeworld.com/articles/read/189/how-to-create-a-file-and-generate-a-download-with-javascript-in-the-browser-without-a-server
function download(filename: string, contentType: string, text: string): void {
Expand Down
7 changes: 5 additions & 2 deletions dev/ts/dev-bundle-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

export * from './main';
export * from './utils/shared-helpers';
export * from './shared/controls';
export * from './shared/main';
export * from './shared/shared-helpers';
export * from '../../src/bpmn-visualization';
// extra code not exported by bpmn-visualization
export * from '../../src/model/bpmn/internal/edge/utils';
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { documentReady, log, logError, startBpmnVisualization } from '../../../ts/dev-bundle-index';
import { documentReady, log, logError, startBpmnVisualization } from '../dev-bundle-index';

function statusFetchKO(errorMsg) {
function statusFetchKO(errorMsg: string): void {
logError(errorMsg);
const statusElt = document.getElementById('status-zone');
statusElt.innerText = errorMsg;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { documentReady, fit, FitType, startBpmnVisualization, zoom, ZoomType } from '../../../ts/dev-bundle-index';
import { configureControlsPanel, configureMousePointer } from './helpers/controls.js';
import { configureControlsPanel, configureMousePointer, documentReady, fit, FitType, startBpmnVisualization, zoom, ZoomType } from '../dev-bundle-index';

function configureFitAndZoomButtons() {
function configureFitAndZoomButtons(): void {
Object.values(FitType).forEach(fitType => {
document.getElementById(fitType).onclick = () => fit({ type: fitType });
});
Expand All @@ -26,23 +25,23 @@ function configureFitAndZoomButtons() {
});
}

function configureZoomThrottleInput(parameters) {
const elZoomThrottle = document.getElementById('zoom-throttle');
function configureZoomThrottleInput(parameters: URLSearchParams): HTMLInputElement {
const elZoomThrottle = <HTMLInputElement>document.getElementById('zoom-throttle');
if (parameters.get('zoomThrottle')) {
elZoomThrottle.value = parameters.get('zoomThrottle');
}
return elZoomThrottle;
}

function configureZoomDebounceInput(parameters) {
const elZoomDebounce = document.getElementById('zoom-debounce');
function configureZoomDebounceInput(parameters: URLSearchParams): HTMLInputElement {
const elZoomDebounce = <HTMLInputElement>document.getElementById('zoom-debounce');
if (parameters.get('zoomDebounce')) {
elZoomDebounce.value = parameters.get('zoomDebounce');
}
return elZoomDebounce;
}

function start() {
function start(): void {
const parameters = new URLSearchParams(window.location.search);
configureMousePointer(parameters);
configureControlsPanel(parameters);
Expand All @@ -56,8 +55,8 @@ function start() {
navigation: {
enabled: true,
zoom: {
throttleDelay: elZoomThrottle.value,
debounceDelay: elZoomDebounce.value,
throttleDelay: Number(elZoomThrottle.value),
debounceDelay: Number(elZoomDebounce.value),
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import type { BpmnElement, BpmnElementKind, Overlay, ShapeStyleUpdate, StyleUpdate, FlowKind } from '../dev-bundle-index';
import {
addCssClasses,
addOverlays,
Expand All @@ -34,17 +35,32 @@ import {
getParentElementIds,
ShapeBpmnElementKind,
isChildOfSubProcess,
} from '../../../ts/dev-bundle-index';
isFlowKind,
} from '../dev-bundle-index';

let lastIdentifiedBpmnIds = [];
let lastIdentifiedParentBpmnIds = [];
let styledPoolAndLaneIds = [];
let lastIdentifiedBpmnIds: string[] = [];
let lastIdentifiedParentBpmnIds: string[] = [];
let styledPoolAndLaneIds: string[] = [];
const cssClassName = 'detection';
let isOverlaysDisplayed = true;
let useCSS = true;

function computeStyleUpdateByKind(bpmnKind) {
const style = { font: {}, fill: {}, stroke: {} };
function computeStyleUpdateByKind(bpmnKind: BpmnElementKind): StyleUpdate {
const style: ShapeStyleUpdate = { font: {}, fill: {}, stroke: {} };

if (isFlowKind(bpmnKind)) {
switch (bpmnKind as FlowKind) {
case 'messageFlow':
case 'sequenceFlow':
case 'association':
style.font.color = 'Chocolate';
style.stroke.color = 'Chocolate';
style.stroke.width = 4;
break;
}
return style;
}

if (ShapeUtil.isTask(bpmnKind)) {
style.font.color = 'Indigo';
style.fill.color = 'gold';
Expand Down Expand Up @@ -99,19 +115,12 @@ function computeStyleUpdateByKind(bpmnKind) {
style.stroke.color = 'Chartreuse';
style.stroke.width = 6;
break;
case 'messageFlow':
case 'sequenceFlow':
case 'association':
style.font.color = 'Chocolate';
style.stroke.color = 'Chocolate';
style.stroke.width = 4;
break;
}
}
return style;
}

function updateStyleByAPI(bpmnIds, bpmnKind) {
function updateStyleByAPI(bpmnIds: string[], bpmnKind: ShapeBpmnElementKind): void {
const subProcessChildrenIds = bpmnIds.filter(isChildOfSubProcess);
const otherIds = bpmnIds.filter(bpmnId => !subProcessChildrenIds.includes(bpmnId));

Expand All @@ -130,25 +139,25 @@ function updateStyleByAPI(bpmnIds, bpmnKind) {
updateStyle(otherIds, style);
}

function styleByCSS(idsToStyle) {
function styleByCSS(idsToStyle: string[]): void {
removeCssClasses(lastIdentifiedBpmnIds, cssClassName);
addCssClasses(idsToStyle, cssClassName);
}

function styleByAPI(idsToStyle, bpmnKind) {
function styleByAPI(idsToStyle: string[], bpmnKind: ShapeBpmnElementKind): void {
resetStyleByAPI();
updateStyleByAPI(idsToStyle, bpmnKind);
}

function resetStyleByAPI() {
function resetStyleByAPI(): void {
resetStyle(lastIdentifiedBpmnIds);
resetStyle(lastIdentifiedParentBpmnIds);
lastIdentifiedParentBpmnIds = [];
resetStyle(styledPoolAndLaneIds);
styledPoolAndLaneIds = [];
}

function manageOverlays(idsToAddOverlay, bpmnKind) {
function manageOverlays(idsToAddOverlay: string[], bpmnKind: ShapeBpmnElementKind): void {
lastIdentifiedBpmnIds.forEach(id => removeAllOverlays(id));
if (isOverlaysDisplayed) {
idsToAddOverlay.forEach(id => addOverlays(id, getOverlay(bpmnKind)));
Expand All @@ -157,7 +166,7 @@ function manageOverlays(idsToAddOverlay, bpmnKind) {
}
}

function updateSelectedBPMNElements(bpmnKind) {
function updateSelectedBPMNElements(bpmnKind: ShapeBpmnElementKind): void {
log(`Searching for Bpmn elements of '${bpmnKind}' kind`);
const elementsByKinds = getElementsByKinds(bpmnKind);

Expand All @@ -172,8 +181,8 @@ function updateSelectedBPMNElements(bpmnKind) {
lastIdentifiedBpmnIds = newlyIdentifiedBpmnIds;
}

function updateTextArea(elementsByKinds, bpmnKind) {
const textArea = document.getElementById('elements-result');
function updateTextArea(elementsByKinds: BpmnElement[], bpmnKind: string): void {
const textArea = <HTMLTextAreaElement>document.getElementById('elements-result');

const textHeader = `Found ${elementsByKinds.length} ${bpmnKind}(s)`;
log(textHeader);
Expand All @@ -183,15 +192,15 @@ function updateTextArea(elementsByKinds, bpmnKind) {
textArea.scrollTop = textArea.scrollHeight;
}

function resetTextArea() {
const textArea = document.getElementById('elements-result');
function resetTextArea(): void {
const textArea = <HTMLTextAreaElement>document.getElementById('elements-result');
textArea.value = '';
}

function configureControls() {
const selectedKindElt = document.getElementById('bpmn-kinds-select');
selectedKindElt.onchange = event => updateSelectedBPMNElements(event.target.value);
document.addEventListener('diagramLoaded', () => updateSelectedBPMNElements(selectedKindElt.value), false);
function configureControls(): void {
const selectedKindElt = <HTMLSelectElement>document.getElementById('bpmn-kinds-select');
selectedKindElt.onchange = event => updateSelectedBPMNElements((<HTMLSelectElement>event.target).value as ShapeBpmnElementKind);
document.addEventListener('diagramLoaded', () => updateSelectedBPMNElements(selectedKindElt.value as ShapeBpmnElementKind), false);

document.getElementById('clear-btn').onclick = function () {
resetTextArea();
Expand All @@ -204,16 +213,16 @@ function configureControls() {
};

// display overlay option
const checkboxDisplayOverlaysElt = document.getElementById('checkbox-display-overlays');
const checkboxDisplayOverlaysElt = <HTMLInputElement>document.getElementById('checkbox-display-overlays');
checkboxDisplayOverlaysElt.addEventListener('change', function () {
isOverlaysDisplayed = this.checked;
log('Request overlays display:', isOverlaysDisplayed);
updateSelectedBPMNElements(selectedKindElt.value);
updateSelectedBPMNElements(selectedKindElt.value as ShapeBpmnElementKind);
});
checkboxDisplayOverlaysElt.checked = isOverlaysDisplayed;

// use CSS or API to style the BPMN elements
const checkboxUseCSSElt = document.getElementById('checkbox-css-style');
const checkboxUseCSSElt = <HTMLInputElement>document.getElementById('checkbox-css-style');
checkboxUseCSSElt.addEventListener('change', function () {
useCSS = this.checked;
log('Request CSS style feature:', useCSS);
Expand All @@ -223,13 +232,13 @@ function configureControls() {
addCssClasses(lastIdentifiedBpmnIds, cssClassName);
} else {
removeCssClasses(lastIdentifiedBpmnIds, cssClassName);
updateStyleByAPI(lastIdentifiedBpmnIds, selectedKindElt.value);
updateStyleByAPI(lastIdentifiedBpmnIds, selectedKindElt.value as ShapeBpmnElementKind);
}
});
checkboxUseCSSElt.checked = useCSS;
}

function getOverlay(bpmnKind) {
function getOverlay(bpmnKind: BpmnElementKind): Overlay {
if (ShapeUtil.isActivity(bpmnKind)) {
return {
position: 'top-right',
Expand Down Expand Up @@ -274,7 +283,7 @@ function getOverlay(bpmnKind) {
return { position: 'top-left', label: '40' };
}

function configureDownloadButtons() {
function configureDownloadButtons(): void {
document.getElementById('btn-dl-svg').addEventListener('click', downloadSvg, false);
document.getElementById('btn-dl-png').addEventListener('click', downloadPng, false);
}
Expand All @@ -283,7 +292,7 @@ documentReady(() => {
startBpmnVisualization({
globalOptions: {
// Use a DOM element without id to test the fix for https://github.com/process-analytics/bpmn-visualization-js/issues/2270
container: document.querySelector('.bpmn-container'),
container: <HTMLElement>document.querySelector('.bpmn-container'),
navigation: {
enabled: true,
},
Expand Down
Loading