@jylups/flowable-simple-view 0.0.0-stage → 0.1.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 +22 -0
- package/LICENSE +21 -0
- package/README.md +112 -2
- package/dist/bpmn.d.ts +6 -0
- package/dist/bpmn.js +4 -0
- package/dist/bpmn.js.map +1 -0
- package/dist/cmmn.d.ts +6 -0
- package/dist/cmmn.js +4 -0
- package/dist/cmmn.js.map +1 -0
- package/dist/core/layout.d.ts +48 -0
- package/dist/core/layout.js +164 -0
- package/dist/core/layout.js.map +1 -0
- package/dist/core/outline.d.ts +76 -0
- package/dist/core/outline.js +432 -0
- package/dist/core/outline.js.map +1 -0
- package/dist/core.d.ts +8 -0
- package/dist/core.js +7 -0
- package/dist/core.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/render/case.d.ts +9 -0
- package/dist/render/case.js +73 -0
- package/dist/render/case.js.map +1 -0
- package/dist/render/common.d.ts +47 -0
- package/dist/render/common.js +109 -0
- package/dist/render/common.js.map +1 -0
- package/dist/render/process.d.ts +17 -0
- package/dist/render/process.js +88 -0
- package/dist/render/process.js.map +1 -0
- package/dist/simple-view.css +347 -0
- package/package.json +84 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `@jylups/flowable-simple-view` are listed here.
|
|
4
|
+
|
|
5
|
+
## Unreleased
|
|
6
|
+
|
|
7
|
+
## 0.1.0 (2026-12-01)
|
|
8
|
+
|
|
9
|
+
The first release.
|
|
10
|
+
|
|
11
|
+
- Repository, CI and release workflow.
|
|
12
|
+
- `processOutline` and `caseOutline`: a BPMN process or a CMMN case plan as a
|
|
13
|
+
plain-language outline. `layoutFlow`: a small left-to-right layered layout.
|
|
14
|
+
The plain-words helpers `plainName`, `plainCondition`, `personaOf`,
|
|
15
|
+
`screenOf` and `humanize`.
|
|
16
|
+
- `renderProcessOutline` and `renderCaseOutline`: the Simple view drawn as
|
|
17
|
+
plain DOM into an element, with `update` and `destroy`, an icon hook, and an
|
|
18
|
+
error box instead of an exception.
|
|
19
|
+
- `simple-view.css`: `fsv-` classes and the custom properties `--fsv-surface`,
|
|
20
|
+
`--fsv-surface-ground`, `--fsv-border`, `--fsv-text`,
|
|
21
|
+
`--fsv-text-secondary`, `--fsv-accent` and `--fsv-font-size`; light and dark
|
|
22
|
+
defaults, forced with `data-fsv-theme`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 jC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,113 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @jylups/flowable-simple-view
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/jylups/flowable-simple-view/actions/workflows/ci.yml)
|
|
4
|
+
|
|
5
|
+
A plain-language box view of Flowable BPMN processes and CMMN case plans, for
|
|
6
|
+
people who don't read BPMN or CMMN diagrams.
|
|
7
|
+
|
|
8
|
+

|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
- **A process** reads left to right: each task in a box with who works it (its
|
|
12
|
+
lane, or its candidate groups and assignee in words) and the form or page it
|
|
13
|
+
shows, the branches named on the arrows, loops drawn back underneath, and
|
|
14
|
+
each event subprocess as its own flow.
|
|
15
|
+
- **A case plan** reads as its stages: in each, the items in the order their
|
|
16
|
+
sentries start them, with what starts each one in plain words, who works it,
|
|
17
|
+
its screen, and whether a user starts it, it repeats or it is required.
|
|
18
|
+
|
|
19
|
+
It reads the model XML with the browser's `DOMParser` and draws plain DOM and
|
|
20
|
+
SVG. It has no framework and no runtime dependencies, and doesn't use bpmn-js,
|
|
21
|
+
cmmn-js, diagram-js or moddle.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
npm install @jylups/flowable-simple-view
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Use
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
import { renderProcessOutline } from '@jylups/flowable-simple-view/bpmn';
|
|
33
|
+
import { renderCaseOutline } from '@jylups/flowable-simple-view/cmmn';
|
|
34
|
+
import '@jylups/flowable-simple-view/simple-view.css';
|
|
35
|
+
|
|
36
|
+
const view = renderProcessOutline(document.querySelector('#simple-view'), bpmnXml);
|
|
37
|
+
|
|
38
|
+
view.update(changedXml); // draw it again, for example after an edit
|
|
39
|
+
view.destroy(); // empty the element
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`renderCaseOutline(element, cmmnXml)` works the same way for a case plan.
|
|
43
|
+
|
|
44
|
+
XML that doesn't parse shows an error box in the element instead of throwing,
|
|
45
|
+
so a view that follows a file being edited keeps working.
|
|
46
|
+
|
|
47
|
+
### Options
|
|
48
|
+
|
|
49
|
+
| Option | What it does |
|
|
50
|
+
|---|---|
|
|
51
|
+
| `icon(name)` | Returns the node for an icon (`user`, `file`, `info`, `play`, `arrow-down`). Defaults to small inline SVG icons; an app can return its own icon font instead. |
|
|
52
|
+
| `boxSize`, `columnGap` | Sizes of the process view's boxes and the room between columns for branch names. |
|
|
53
|
+
| `onError(message)` | Called when the XML can't be shown. |
|
|
54
|
+
| `showError` | `false` leaves the error message to the app (default `true`: an error box in the view). |
|
|
55
|
+
|
|
56
|
+
### Without the DOM view
|
|
57
|
+
|
|
58
|
+
The outlines themselves are plain objects, for apps that draw them their own
|
|
59
|
+
way:
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { processOutline } from '@jylups/flowable-simple-view/bpmn';
|
|
63
|
+
import { caseOutline } from '@jylups/flowable-simple-view/cmmn';
|
|
64
|
+
import { layoutFlow, plainCondition } from '@jylups/flowable-simple-view/core';
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Styling
|
|
68
|
+
|
|
69
|
+
Every class starts with `fsv-`. Colours and sizes are custom properties on
|
|
70
|
+
`.fsv`, so an app restyles the view by setting them on the element or any
|
|
71
|
+
ancestor:
|
|
72
|
+
|
|
73
|
+
| Property | Used for |
|
|
74
|
+
|---|---|
|
|
75
|
+
| `--fsv-surface` | Box background |
|
|
76
|
+
| `--fsv-surface-ground` | Stage background |
|
|
77
|
+
| `--fsv-border` | Box and stage borders |
|
|
78
|
+
| `--fsv-text` | Text |
|
|
79
|
+
| `--fsv-text-secondary` | Kinds, arrows, secondary lines |
|
|
80
|
+
| `--fsv-accent` | The edge of task boxes |
|
|
81
|
+
| `--fsv-font-size` | Base font size |
|
|
82
|
+
|
|
83
|
+
For example, an app with a PrimeNG theme:
|
|
84
|
+
|
|
85
|
+
```css
|
|
86
|
+
.fsv {
|
|
87
|
+
--fsv-surface: var(--surface-card);
|
|
88
|
+
--fsv-surface-ground: var(--surface-ground);
|
|
89
|
+
--fsv-border: var(--surface-border);
|
|
90
|
+
--fsv-text: var(--text-color);
|
|
91
|
+
--fsv-text-secondary: var(--text-color-secondary);
|
|
92
|
+
--fsv-accent: var(--primary-color);
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
The defaults are light, and dark when the system prefers dark. An app with its
|
|
97
|
+
own theme switch sets `data-fsv-theme="dark"` or `data-fsv-theme="light"` on
|
|
98
|
+
the element or an ancestor.
|
|
99
|
+
|
|
100
|
+
## Development
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
npm install
|
|
104
|
+
npm run all # lint, type check, tests, build, and a check of what npm would publish
|
|
105
|
+
npm run dev # tests in watch mode
|
|
106
|
+
npm run demo # the made-up models of test/fixtures in the Simple view, light and dark
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Releases: see [RELEASING.md](RELEASING.md).
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
MIT
|
package/dist/bpmn.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The Simple view of a BPMN process. */
|
|
2
|
+
export { processOutline } from './core/outline.js';
|
|
3
|
+
export type { FlowNode, FlowEdge, FlowSection, ProcessOutline } from './core/outline.js';
|
|
4
|
+
export { renderProcessOutline } from './render/process.js';
|
|
5
|
+
export type { ProcessViewOptions } from './render/process.js';
|
|
6
|
+
export type { IconName, SimpleView, SimpleViewOptions } from './render/common.js';
|
package/dist/bpmn.js
ADDED
package/dist/bpmn.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bpmn.js","sourceRoot":"","sources":["../src/bpmn.ts"],"names":[],"mappings":"AAAA,yCAAyC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["/** The Simple view of a BPMN process. */\n\nexport { processOutline } from './core/outline.js';\nexport type { FlowNode, FlowEdge, FlowSection, ProcessOutline } from './core/outline.js';\nexport { renderProcessOutline } from './render/process.js';\nexport type { ProcessViewOptions } from './render/process.js';\nexport type { IconName, SimpleView, SimpleViewOptions } from './render/common.js';\n"]}
|
package/dist/cmmn.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** The Simple view of a CMMN case plan. */
|
|
2
|
+
export { caseOutline } from './core/outline.js';
|
|
3
|
+
export type { CaseItem, CaseOutline } from './core/outline.js';
|
|
4
|
+
export { renderCaseOutline } from './render/case.js';
|
|
5
|
+
export type { CaseViewOptions } from './render/case.js';
|
|
6
|
+
export type { IconName, SimpleView, SimpleViewOptions } from './render/common.js';
|
package/dist/cmmn.js
ADDED
package/dist/cmmn.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cmmn.js","sourceRoot":"","sources":["../src/cmmn.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC","sourcesContent":["/** The Simple view of a CMMN case plan. */\n\nexport { caseOutline } from './core/outline.js';\nexport type { CaseItem, CaseOutline } from './core/outline.js';\nexport { renderCaseOutline } from './render/case.js';\nexport type { CaseViewOptions } from './render/case.js';\nexport type { IconName, SimpleView, SimpleViewOptions } from './render/common.js';\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small left-to-right layered layout for the process box view: each node
|
|
3
|
+
* goes one column after the latest node that leads to it, loops are drawn as
|
|
4
|
+
* arrows back underneath, and each column's nodes are ordered to keep arrows
|
|
5
|
+
* short.
|
|
6
|
+
*/
|
|
7
|
+
export interface LayoutNodeInput {
|
|
8
|
+
id: string;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
}
|
|
12
|
+
export interface LayoutEdgeInput {
|
|
13
|
+
id: string;
|
|
14
|
+
from: string;
|
|
15
|
+
to: string;
|
|
16
|
+
}
|
|
17
|
+
export interface PlacedNode {
|
|
18
|
+
id: string;
|
|
19
|
+
x: number;
|
|
20
|
+
y: number;
|
|
21
|
+
width: number;
|
|
22
|
+
height: number;
|
|
23
|
+
column: number;
|
|
24
|
+
}
|
|
25
|
+
export interface PlacedEdge {
|
|
26
|
+
id: string;
|
|
27
|
+
/** An SVG path from the source to the target. */
|
|
28
|
+
path: string;
|
|
29
|
+
/** Where the label goes. */
|
|
30
|
+
labelX: number;
|
|
31
|
+
labelY: number;
|
|
32
|
+
/** The arrow goes back to an earlier column (a loop). */
|
|
33
|
+
back: boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface FlowLayout {
|
|
36
|
+
nodes: Map<string, PlacedNode>;
|
|
37
|
+
edges: PlacedEdge[];
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
}
|
|
41
|
+
export interface FlowLayoutOptions {
|
|
42
|
+
columnGap: number;
|
|
43
|
+
rowGap: number;
|
|
44
|
+
margin: number;
|
|
45
|
+
/** How far below the nodes each loop arrow runs. */
|
|
46
|
+
loopGap: number;
|
|
47
|
+
}
|
|
48
|
+
export declare function layoutFlow(nodes: LayoutNodeInput[], edges: LayoutEdgeInput[], options?: Partial<FlowLayoutOptions>): FlowLayout;
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A small left-to-right layered layout for the process box view: each node
|
|
3
|
+
* goes one column after the latest node that leads to it, loops are drawn as
|
|
4
|
+
* arrows back underneath, and each column's nodes are ordered to keep arrows
|
|
5
|
+
* short.
|
|
6
|
+
*/
|
|
7
|
+
/** The height a waypoint takes in its column. */
|
|
8
|
+
const WAYPOINT_HEIGHT = 12;
|
|
9
|
+
const DEFAULTS = { columnGap: 90, rowGap: 36, margin: 24, loopGap: 28 };
|
|
10
|
+
export function layoutFlow(nodes, edges, options = {}) {
|
|
11
|
+
const settings = { ...DEFAULTS, ...options };
|
|
12
|
+
const ids = new Set(nodes.map((node) => node.id));
|
|
13
|
+
const links = edges.filter((edge) => ids.has(edge.from) && ids.has(edge.to) && edge.from !== edge.to);
|
|
14
|
+
const outgoing = new Map(nodes.map((node) => [node.id, []]));
|
|
15
|
+
const incomingCount = new Map(nodes.map((node) => [node.id, 0]));
|
|
16
|
+
links.forEach((edge) => {
|
|
17
|
+
outgoing.get(edge.from).push(edge);
|
|
18
|
+
incomingCount.set(edge.to, incomingCount.get(edge.to) + 1);
|
|
19
|
+
});
|
|
20
|
+
// depth-first from the nodes nothing leads to (in model order), then from any node left: an arrow to a node on the path is a loop
|
|
21
|
+
const back = new Set();
|
|
22
|
+
const discovered = new Map();
|
|
23
|
+
const onPath = new Set();
|
|
24
|
+
const visit = (id) => {
|
|
25
|
+
discovered.set(id, discovered.size);
|
|
26
|
+
onPath.add(id);
|
|
27
|
+
outgoing.get(id).forEach((edge) => {
|
|
28
|
+
if (onPath.has(edge.to)) {
|
|
29
|
+
back.add(edge.id);
|
|
30
|
+
}
|
|
31
|
+
else if (!discovered.has(edge.to)) {
|
|
32
|
+
visit(edge.to);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
onPath.delete(id);
|
|
36
|
+
};
|
|
37
|
+
nodes.filter((node) => incomingCount.get(node.id) === 0).forEach((node) => discovered.has(node.id) || visit(node.id));
|
|
38
|
+
nodes.forEach((node) => discovered.has(node.id) || visit(node.id));
|
|
39
|
+
// column: the longest path of forward arrows that leads to the node
|
|
40
|
+
const forward = links.filter((edge) => !back.has(edge.id));
|
|
41
|
+
const column = new Map(nodes.map((node) => [node.id, 0]));
|
|
42
|
+
const pending = new Map(nodes.map((node) => [node.id, 0]));
|
|
43
|
+
forward.forEach((edge) => pending.set(edge.to, pending.get(edge.to) + 1));
|
|
44
|
+
const queue = nodes.filter((node) => pending.get(node.id) === 0).map((node) => node.id);
|
|
45
|
+
while (queue.length) {
|
|
46
|
+
const id = queue.shift();
|
|
47
|
+
forward
|
|
48
|
+
.filter((edge) => edge.from === id)
|
|
49
|
+
.forEach((edge) => {
|
|
50
|
+
column.set(edge.to, Math.max(column.get(edge.to), column.get(id) + 1));
|
|
51
|
+
pending.set(edge.to, pending.get(edge.to) - 1);
|
|
52
|
+
if (pending.get(edge.to) === 0) {
|
|
53
|
+
queue.push(edge.to);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
const columnCount = Math.max(0, ...column.values()) + 1;
|
|
58
|
+
const columns = Array.from({ length: columnCount }, () => []);
|
|
59
|
+
[...nodes].sort((a, b) => discovered.get(a.id) - discovered.get(b.id)).forEach((node) => columns[column.get(node.id)].push(node.id));
|
|
60
|
+
// an arrow that skips columns gets a waypoint in each column it crosses, so that it passes between the nodes
|
|
61
|
+
const byId = new Map(nodes.map((node) => [node.id, node]));
|
|
62
|
+
const waypoints = new Map();
|
|
63
|
+
const steps = [];
|
|
64
|
+
forward.forEach((edge) => {
|
|
65
|
+
const from = column.get(edge.from);
|
|
66
|
+
const span = column.get(edge.to) - from;
|
|
67
|
+
if (span <= 1) {
|
|
68
|
+
steps.push(edge);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const ids = Array.from({ length: span - 1 }, (_, i) => `${edge.id}~${i}`);
|
|
72
|
+
ids.forEach((id, i) => {
|
|
73
|
+
byId.set(id, { id, width: 1, height: WAYPOINT_HEIGHT });
|
|
74
|
+
columns[from + 1 + i].push(id);
|
|
75
|
+
});
|
|
76
|
+
[edge.from, ...ids, edge.to].slice(1).forEach((to, i, rest) => steps.push({ id: `${edge.id}#${i}`, from: i === 0 ? edge.from : rest[i - 1], to }));
|
|
77
|
+
waypoints.set(edge.id, ids);
|
|
78
|
+
});
|
|
79
|
+
// order each column by where its neighbours sit (a few sweeps left to right and back)
|
|
80
|
+
const position = new Map();
|
|
81
|
+
const index = () => columns.forEach((ids) => ids.forEach((id, i) => position.set(id, i)));
|
|
82
|
+
const neighbours = (id, before) => steps.filter((edge) => (before ? edge.to === id : edge.from === id)).map((edge) => (before ? edge.from : edge.to));
|
|
83
|
+
const sortColumn = (ids, before) => {
|
|
84
|
+
const weight = new Map(ids.map((id) => {
|
|
85
|
+
const near = neighbours(id, before).map((other) => position.get(other));
|
|
86
|
+
return [id, near.length ? near.reduce((sum, value) => sum + value, 0) / near.length : position.get(id)];
|
|
87
|
+
}));
|
|
88
|
+
ids.sort((a, b) => weight.get(a) - weight.get(b) || position.get(a) - position.get(b));
|
|
89
|
+
};
|
|
90
|
+
index();
|
|
91
|
+
for (let sweep = 0; sweep < 4; sweep++) {
|
|
92
|
+
for (let c = 1; c < columnCount; c++) {
|
|
93
|
+
sortColumn(columns[c], true);
|
|
94
|
+
index();
|
|
95
|
+
}
|
|
96
|
+
for (let c = columnCount - 2; c >= 0; c--) {
|
|
97
|
+
sortColumn(columns[c], false);
|
|
98
|
+
index();
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
// place the columns left to right, each centred on the tallest
|
|
102
|
+
const columnWidth = columns.map((ids) => Math.max(0, ...ids.map((id) => byId.get(id).width)));
|
|
103
|
+
const columnHeight = columns.map((ids) => ids.reduce((sum, id) => sum + byId.get(id).height, 0) + Math.max(0, ids.length - 1) * settings.rowGap);
|
|
104
|
+
const tallest = Math.max(0, ...columnHeight);
|
|
105
|
+
const placed = new Map();
|
|
106
|
+
const columnLeft = [];
|
|
107
|
+
let x = settings.margin;
|
|
108
|
+
columns.forEach((ids, c) => {
|
|
109
|
+
columnLeft[c] = x;
|
|
110
|
+
let y = settings.margin + (tallest - columnHeight[c]) / 2;
|
|
111
|
+
ids.forEach((id) => {
|
|
112
|
+
const node = byId.get(id);
|
|
113
|
+
placed.set(id, { id, x: x + (columnWidth[c] - node.width) / 2, y, width: node.width, height: node.height, column: c });
|
|
114
|
+
y += node.height + settings.rowGap;
|
|
115
|
+
});
|
|
116
|
+
x += columnWidth[c] + settings.columnGap;
|
|
117
|
+
});
|
|
118
|
+
const bottom = settings.margin + tallest;
|
|
119
|
+
let loops = 0;
|
|
120
|
+
const placedEdges = links.map((edge) => {
|
|
121
|
+
const source = placed.get(edge.from);
|
|
122
|
+
const target = placed.get(edge.to);
|
|
123
|
+
if (back.has(edge.id) || target.column <= source.column) {
|
|
124
|
+
// a loop runs underneath, back to its target
|
|
125
|
+
const sx = source.x + source.width / 2;
|
|
126
|
+
const sy = source.y + source.height;
|
|
127
|
+
const ex = target.x + target.width / 2;
|
|
128
|
+
const ey = target.y + target.height;
|
|
129
|
+
const below = bottom + settings.loopGap * ++loops;
|
|
130
|
+
return { id: edge.id, path: `M ${sx} ${sy} C ${sx} ${below}, ${ex} ${below}, ${ex} ${ey}`, labelX: (sx + ex) / 2, labelY: below - settings.loopGap / 4, back: true };
|
|
131
|
+
}
|
|
132
|
+
// from the source's right side, through the waypoints, to the target's left side
|
|
133
|
+
const points = [
|
|
134
|
+
{ x: source.x + source.width, y: source.y + source.height / 2 },
|
|
135
|
+
...(waypoints.get(edge.id) || []).map((id) => {
|
|
136
|
+
const point = placed.get(id);
|
|
137
|
+
return { x: point.x, y: point.y + point.height / 2 };
|
|
138
|
+
}),
|
|
139
|
+
{ x: target.x, y: target.y + target.height / 2 }
|
|
140
|
+
];
|
|
141
|
+
const path = points
|
|
142
|
+
.slice(1)
|
|
143
|
+
.map((point, i) => {
|
|
144
|
+
const start = points[i];
|
|
145
|
+
const bend = Math.max(20, (point.x - start.x) / 2);
|
|
146
|
+
return `C ${start.x + bend} ${start.y}, ${point.x - bend} ${point.y}, ${point.x} ${point.y}`;
|
|
147
|
+
})
|
|
148
|
+
.join(' ');
|
|
149
|
+
// the label sits in the gap after the source, on the arrow's first curve
|
|
150
|
+
const gapEnd = columnLeft[source.column + 1] ?? points[1].x;
|
|
151
|
+
const labelX = (points[0].x + Math.min(gapEnd, points[1].x)) / 2;
|
|
152
|
+
const t = Math.min(1, Math.max(0, (labelX - points[0].x) / (points[1].x - points[0].x || 1)));
|
|
153
|
+
const labelY = points[0].y + (points[1].y - points[0].y) * (3 * t * t - 2 * t * t * t);
|
|
154
|
+
return { id: edge.id, path: `M ${points[0].x} ${points[0].y} ${path}`, labelX, labelY, back: false };
|
|
155
|
+
});
|
|
156
|
+
waypoints.forEach((ids) => ids.forEach((id) => placed.delete(id)));
|
|
157
|
+
return {
|
|
158
|
+
nodes: placed,
|
|
159
|
+
edges: placedEdges,
|
|
160
|
+
width: Math.max(settings.margin * 2, x - settings.columnGap + settings.margin),
|
|
161
|
+
height: bottom + settings.margin + settings.loopGap * loops
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=layout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"layout.js","sourceRoot":"","sources":["../../src/core/layout.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAiDH,iDAAiD;AACjD,MAAM,eAAe,GAAG,EAAE,CAAC;AAE3B,MAAM,QAAQ,GAAsB,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAE3F,MAAM,UAAU,UAAU,CAAC,KAAwB,EAAE,KAAwB,EAAE,UAAsC,EAAE;IACnH,MAAM,QAAQ,GAAG,EAAE,GAAG,QAAQ,EAAE,GAAG,OAAO,EAAE,CAAC;IAC7C,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IAClD,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC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goes one column after the latest node that leads to it, loops are drawn as\n * arrows back underneath, and each column's nodes are ordered to keep arrows\n * short.\n */\n\nexport interface LayoutNodeInput {\n id: string;\n width: number;\n height: number;\n}\n\nexport interface LayoutEdgeInput {\n id: string;\n from: string;\n to: string;\n}\n\nexport interface PlacedNode {\n id: string;\n x: number;\n y: number;\n width: number;\n height: number;\n column: number;\n}\n\nexport interface PlacedEdge {\n id: string;\n /** An SVG path from the source to the target. */\n path: string;\n /** Where the label goes. */\n labelX: number;\n labelY: number;\n /** The arrow goes back to an earlier column (a loop). */\n back: boolean;\n}\n\nexport interface FlowLayout {\n nodes: Map<string, PlacedNode>;\n edges: PlacedEdge[];\n width: number;\n height: number;\n}\n\nexport interface FlowLayoutOptions {\n columnGap: number;\n rowGap: number;\n margin: number;\n /** How far below the nodes each loop arrow runs. */\n loopGap: number;\n}\n\n/** The height a waypoint takes in its column. */\nconst WAYPOINT_HEIGHT = 12;\n\nconst DEFAULTS: FlowLayoutOptions = { columnGap: 90, rowGap: 36, margin: 24, loopGap: 28 };\n\nexport function layoutFlow(nodes: LayoutNodeInput[], edges: LayoutEdgeInput[], options: Partial<FlowLayoutOptions> = {}): FlowLayout {\n const settings = { ...DEFAULTS, ...options };\n const ids = new Set(nodes.map((node) => node.id));\n const links = edges.filter((edge) => ids.has(edge.from) && ids.has(edge.to) && edge.from !== edge.to);\n const outgoing = new Map<string, LayoutEdgeInput[]>(nodes.map((node) => [node.id, []]));\n const incomingCount = new Map<string, number>(nodes.map((node) => [node.id, 0]));\n\n links.forEach((edge) => {\n outgoing.get(edge.from)!.push(edge);\n incomingCount.set(edge.to, incomingCount.get(edge.to)! + 1);\n });\n\n // depth-first from the nodes nothing leads to (in model order), then from any node left: an arrow to a node on the path is a loop\n const back = new Set<string>();\n const discovered = new Map<string, number>();\n const onPath = new Set<string>();\n\n const visit = (id: string) => {\n discovered.set(id, discovered.size);\n onPath.add(id);\n outgoing.get(id)!.forEach((edge) => {\n if (onPath.has(edge.to)) {\n back.add(edge.id);\n } else if (!discovered.has(edge.to)) {\n visit(edge.to);\n }\n });\n onPath.delete(id);\n };\n\n nodes.filter((node) => incomingCount.get(node.id) === 0).forEach((node) => discovered.has(node.id) || visit(node.id));\n nodes.forEach((node) => discovered.has(node.id) || visit(node.id));\n\n // column: the longest path of forward arrows that leads to the node\n const forward = links.filter((edge) => !back.has(edge.id));\n const column = new Map<string, number>(nodes.map((node) => [node.id, 0]));\n const pending = new Map<string, number>(nodes.map((node) => [node.id, 0]));\n\n forward.forEach((edge) => pending.set(edge.to, pending.get(edge.to)! + 1));\n\n const queue = nodes.filter((node) => pending.get(node.id) === 0).map((node) => node.id);\n\n while (queue.length) {\n const id = queue.shift()!;\n\n forward\n .filter((edge) => edge.from === id)\n .forEach((edge) => {\n column.set(edge.to, Math.max(column.get(edge.to)!, column.get(id)! + 1));\n pending.set(edge.to, pending.get(edge.to)! - 1);\n\n if (pending.get(edge.to) === 0) {\n queue.push(edge.to);\n }\n });\n }\n\n const columnCount = Math.max(0, ...column.values()) + 1;\n const columns: string[][] = Array.from({ length: columnCount }, () => []);\n\n [...nodes].sort((a, b) => discovered.get(a.id)! - discovered.get(b.id)!).forEach((node) => columns[column.get(node.id)!].push(node.id));\n\n // an arrow that skips columns gets a waypoint in each column it crosses, so that it passes between the nodes\n const byId = new Map(nodes.map((node) => [node.id, node]));\n const waypoints = new Map<string, string[]>();\n const steps: LayoutEdgeInput[] = [];\n\n forward.forEach((edge) => {\n const from = column.get(edge.from)!;\n const span = column.get(edge.to)! - from;\n\n if (span <= 1) {\n steps.push(edge);\n return;\n }\n\n const ids = Array.from({ length: span - 1 }, (_, i) => `${edge.id}~${i}`);\n\n ids.forEach((id, i) => {\n byId.set(id, { id, width: 1, height: WAYPOINT_HEIGHT });\n columns[from + 1 + i].push(id);\n });\n [edge.from, ...ids, edge.to].slice(1).forEach((to, i, rest) => steps.push({ id: `${edge.id}#${i}`, from: i === 0 ? edge.from : rest[i - 1], to }));\n waypoints.set(edge.id, ids);\n });\n\n // order each column by where its neighbours sit (a few sweeps left to right and back)\n const position = new Map<string, number>();\n const index = () => columns.forEach((ids) => ids.forEach((id, i) => position.set(id, i)));\n const neighbours = (id: string, before: boolean) => steps.filter((edge) => (before ? edge.to === id : edge.from === id)).map((edge) => (before ? edge.from : edge.to));\n const sortColumn = (ids: string[], before: boolean) => {\n const weight = new Map(\n ids.map((id) => {\n const near = neighbours(id, before).map((other) => position.get(other)!);\n return [id, near.length ? near.reduce((sum, value) => sum + value, 0) / near.length : position.get(id)!];\n })\n );\n ids.sort((a, b) => weight.get(a)! - weight.get(b)! || position.get(a)! - position.get(b)!);\n };\n\n index();\n for (let sweep = 0; sweep < 4; sweep++) {\n for (let c = 1; c < columnCount; c++) {\n sortColumn(columns[c], true);\n index();\n }\n for (let c = columnCount - 2; c >= 0; c--) {\n sortColumn(columns[c], false);\n index();\n }\n }\n\n // place the columns left to right, each centred on the tallest\n const columnWidth = columns.map((ids) => Math.max(0, ...ids.map((id) => byId.get(id)!.width)));\n const columnHeight = columns.map((ids) => ids.reduce((sum, id) => sum + byId.get(id)!.height, 0) + Math.max(0, ids.length - 1) * settings.rowGap);\n const tallest = Math.max(0, ...columnHeight);\n const placed = new Map<string, PlacedNode>();\n const columnLeft: number[] = [];\n let x = settings.margin;\n\n columns.forEach((ids, c) => {\n columnLeft[c] = x;\n let y = settings.margin + (tallest - columnHeight[c]) / 2;\n\n ids.forEach((id) => {\n const node = byId.get(id)!;\n\n placed.set(id, { id, x: x + (columnWidth[c] - node.width) / 2, y, width: node.width, height: node.height, column: c });\n y += node.height + settings.rowGap;\n });\n x += columnWidth[c] + settings.columnGap;\n });\n\n const bottom = settings.margin + tallest;\n let loops = 0;\n\n const placedEdges = links.map((edge): PlacedEdge => {\n const source = placed.get(edge.from)!;\n const target = placed.get(edge.to)!;\n\n if (back.has(edge.id) || target.column <= source.column) {\n // a loop runs underneath, back to its target\n const sx = source.x + source.width / 2;\n const sy = source.y + source.height;\n const ex = target.x + target.width / 2;\n const ey = target.y + target.height;\n const below = bottom + settings.loopGap * ++loops;\n\n return { id: edge.id, path: `M ${sx} ${sy} C ${sx} ${below}, ${ex} ${below}, ${ex} ${ey}`, labelX: (sx + ex) / 2, labelY: below - settings.loopGap / 4, back: true };\n }\n\n // from the source's right side, through the waypoints, to the target's left side\n const points = [\n { x: source.x + source.width, y: source.y + source.height / 2 },\n ...(waypoints.get(edge.id) || []).map((id) => {\n const point = placed.get(id)!;\n return { x: point.x, y: point.y + point.height / 2 };\n }),\n { x: target.x, y: target.y + target.height / 2 }\n ];\n const path = points\n .slice(1)\n .map((point, i) => {\n const start = points[i];\n const bend = Math.max(20, (point.x - start.x) / 2);\n return `C ${start.x + bend} ${start.y}, ${point.x - bend} ${point.y}, ${point.x} ${point.y}`;\n })\n .join(' ');\n\n // the label sits in the gap after the source, on the arrow's first curve\n const gapEnd = columnLeft[source.column + 1] ?? points[1].x;\n const labelX = (points[0].x + Math.min(gapEnd, points[1].x)) / 2;\n const t = Math.min(1, Math.max(0, (labelX - points[0].x) / (points[1].x - points[0].x || 1)));\n const labelY = points[0].y + (points[1].y - points[0].y) * (3 * t * t - 2 * t * t * t);\n\n return { id: edge.id, path: `M ${points[0].x} ${points[0].y} ${path}`, labelX, labelY, back: false };\n });\n\n waypoints.forEach((ids) => ids.forEach((id) => placed.delete(id)));\n\n return {\n nodes: placed,\n edges: placedEdges,\n width: Math.max(settings.margin * 2, x - settings.columnGap + settings.margin),\n height: bottom + settings.margin + settings.loopGap * loops\n };\n}\n"]}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plain-language outlines of Flowable models: who works each task, which
|
|
3
|
+
* screen it shows, what starts it and where the flow branches, read from the
|
|
4
|
+
* BPMN or CMMN XML.
|
|
5
|
+
*/
|
|
6
|
+
/** A box of an outline: a task, step, event or stage. */
|
|
7
|
+
export interface OutlineBox {
|
|
8
|
+
id: string;
|
|
9
|
+
/** The element type, for example userTask or humanTask. */
|
|
10
|
+
kind: string;
|
|
11
|
+
/** The kind in plain words, for example Task, Automatic step or Runs process. */
|
|
12
|
+
kindLabel: string;
|
|
13
|
+
/** The name, with run-time values shown as [variable]. */
|
|
14
|
+
name: string;
|
|
15
|
+
/** Who works it, in plain words. */
|
|
16
|
+
persona?: string;
|
|
17
|
+
/** More about who works it, when the persona comes from a lane. */
|
|
18
|
+
personaDetail?: string;
|
|
19
|
+
/** The form or page it shows. */
|
|
20
|
+
screen?: string;
|
|
21
|
+
/** Another line, for example the process it runs. */
|
|
22
|
+
detail?: string;
|
|
23
|
+
}
|
|
24
|
+
/** A node of a process flow. */
|
|
25
|
+
export interface FlowNode extends OutlineBox {
|
|
26
|
+
shape: 'task' | 'gateway' | 'event';
|
|
27
|
+
}
|
|
28
|
+
/** An arrow of a process flow, with the branch in plain words. */
|
|
29
|
+
export interface FlowEdge {
|
|
30
|
+
id: string;
|
|
31
|
+
from: string;
|
|
32
|
+
to: string;
|
|
33
|
+
label?: string;
|
|
34
|
+
}
|
|
35
|
+
/** A connected part of a process: the main flow, or an event subprocess. */
|
|
36
|
+
export interface FlowSection {
|
|
37
|
+
title?: string;
|
|
38
|
+
nodes: FlowNode[];
|
|
39
|
+
edges: FlowEdge[];
|
|
40
|
+
}
|
|
41
|
+
export interface ProcessOutline {
|
|
42
|
+
name: string;
|
|
43
|
+
sections: FlowSection[];
|
|
44
|
+
}
|
|
45
|
+
/** A plan item of a case plan. */
|
|
46
|
+
export interface CaseItem extends OutlineBox {
|
|
47
|
+
/** What starts it, one line per entry criterion. */
|
|
48
|
+
startsWhen: string[];
|
|
49
|
+
repeats: boolean;
|
|
50
|
+
/** A user starts it (manual activation). */
|
|
51
|
+
manual: boolean;
|
|
52
|
+
required: boolean;
|
|
53
|
+
/** The items of a stage, in rows: each row starts after items of earlier rows. */
|
|
54
|
+
rows?: CaseItem[][];
|
|
55
|
+
/** The event listeners of a stage. */
|
|
56
|
+
events?: CaseItem[];
|
|
57
|
+
}
|
|
58
|
+
export interface CaseOutline {
|
|
59
|
+
name: string;
|
|
60
|
+
/** The case plan itself, as a stage. */
|
|
61
|
+
plan: CaseItem;
|
|
62
|
+
}
|
|
63
|
+
/** "orderReviewer" → "Order reviewer". */
|
|
64
|
+
export declare function humanize(identifier: string): string;
|
|
65
|
+
/** A name with its run-time values shown as [variable]: "Approve ${orderId}" → "Approve [orderId]". */
|
|
66
|
+
export declare function plainName(text: string | null | undefined): string;
|
|
67
|
+
/** An expression in plain words, shortened: ${vars:equals(decision, "REJECTED")} → decision is REJECTED. */
|
|
68
|
+
export declare function plainCondition(expression: string | null | undefined): string;
|
|
69
|
+
/** Who works a task, from its candidate groups and users and its assignee. */
|
|
70
|
+
export declare function personaOf(element: Element, namespace: string): string | undefined;
|
|
71
|
+
/** The form or page a task shows: a key starting with / is a page. */
|
|
72
|
+
export declare function screenOf(formKey: string | null | undefined): string | undefined;
|
|
73
|
+
/** The outline of a BPMN process model: its flow, and each event subprocess on its own. */
|
|
74
|
+
export declare function processOutline(xml: string): ProcessOutline;
|
|
75
|
+
/** The outline of a CMMN case plan: its stages, and in each the items in the order their sentries start them. */
|
|
76
|
+
export declare function caseOutline(xml: string): CaseOutline;
|