@jive-sh/workflow-platform 1.0.0 → 1.2.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/README.md +10 -4
- package/component/_generated/component.ts +10 -2
- package/component/engine.ts +5 -4
- package/component/notes.ts +7 -1
- package/component/schema.ts +3 -0
- package/component/store.ts +4 -3
- package/component/tasks.ts +2 -1
- package/dashboard/README.md +57 -0
- package/dashboard/activity-look.ts +93 -0
- package/dashboard/bpmn-moddle.d.ts +9 -0
- package/dashboard/dashboard.css +31 -0
- package/dashboard/figures.test.ts +120 -0
- package/dashboard/figures.ts +125 -0
- package/dashboard/index.ts +14 -0
- package/dashboard/layout.test.ts +82 -0
- package/dashboard/layout.ts +168 -0
- package/dashboard/live.ts +334 -0
- package/dashboard/panel.test.ts +72 -0
- package/dashboard/panel.ts +144 -0
- package/dashboard/pie.test.ts +38 -0
- package/dashboard/pie.ts +86 -0
- package/dashboard/places.test.ts +60 -0
- package/dashboard/places.ts +85 -0
- package/dashboard/shapes.ts +39 -0
- package/dashboard/view.ts +192 -0
- package/dashboard/words.test.ts +61 -0
- package/dashboard/words.ts +61 -0
- package/dist/definition/workflow.js +6 -0
- package/dist/definition/workflow.js.map +1 -1
- package/dist/graph.js +10 -1
- package/dist/graph.js.map +1 -1
- package/package.json +27 -3
- package/src/definition/workflow.ts +7 -0
- package/src/graph.ts +12 -1
- package/worker/platform-client.ts +7 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// The panel beside a workflow's diagram: the tasks at the step or line that was clicked, and for a step its access, its
|
|
2
|
+
// stats and its latest finished runs with links to their transcripts. Every value is in words and numbers, never colour
|
|
3
|
+
// alone.
|
|
4
|
+
import { dollars, duration, millions, number } from "./words"
|
|
5
|
+
|
|
6
|
+
/** The tasks at one place (a queue or a step), in queue order (oldest first). */
|
|
7
|
+
export interface PlaceTasks {
|
|
8
|
+
readonly total: number
|
|
9
|
+
/** The first `tasks.length` of `total`, oldest first. */
|
|
10
|
+
readonly tasks: ReadonlyArray<{
|
|
11
|
+
readonly name: string
|
|
12
|
+
readonly enteredAt: number
|
|
13
|
+
readonly lastNote: string | null
|
|
14
|
+
/** Who holds a task in a step and which try it is, when known. */
|
|
15
|
+
readonly detail?: string
|
|
16
|
+
}>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** What a step has done. */
|
|
20
|
+
export interface StepStats {
|
|
21
|
+
readonly calls: number
|
|
22
|
+
/** Null for a step that spends no tokens. */
|
|
23
|
+
readonly tokens: { readonly input: number; readonly output: number } | null
|
|
24
|
+
readonly timePerTaskMs: { readonly median: number; readonly p90: number }
|
|
25
|
+
readonly endStates: ReadonlyArray<{ readonly end: string; readonly runs: number }>
|
|
26
|
+
/** Which runs the figures cover, in words. */
|
|
27
|
+
readonly over: string
|
|
28
|
+
/** Where a figure comes from when it is not the step's own record, in words. */
|
|
29
|
+
readonly notes?: ReadonlyArray<string>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** One finished run of a step, as the panel lists it: whose task, how it ended, what it spent, and links to its transcripts. */
|
|
33
|
+
export interface StepRun {
|
|
34
|
+
readonly taskName: string
|
|
35
|
+
readonly call: number
|
|
36
|
+
readonly endedAt: number
|
|
37
|
+
readonly endState: string | null
|
|
38
|
+
/** Why the run failed, when it did. */
|
|
39
|
+
readonly error: string | null
|
|
40
|
+
readonly agent: string | null
|
|
41
|
+
/** Null for a step with no agent. */
|
|
42
|
+
readonly tokens: number | null
|
|
43
|
+
readonly costUsd: number | null
|
|
44
|
+
readonly transcripts: ReadonlyArray<{ readonly name: string; readonly href: string | null }>
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The latest finished runs of a step, and which runs they are, in words. */
|
|
48
|
+
export interface StepRuns {
|
|
49
|
+
readonly runs: ReadonlyArray<StepRun>
|
|
50
|
+
readonly from: string
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const escape = (text: string): string =>
|
|
54
|
+
text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """)
|
|
55
|
+
|
|
56
|
+
const noteOf = (lastNote: string | null): string => (lastNote === null ? "No note yet" : `Last note: ${escape(lastNote)}`)
|
|
57
|
+
|
|
58
|
+
const taskList = (place: PlaceTasks, now: number, waiting: boolean): string => {
|
|
59
|
+
if (place.total === 0) return `<p class="jive-empty">No tasks ${waiting ? "waiting here" : "in this step"} now.</p>`
|
|
60
|
+
const rows = place.tasks
|
|
61
|
+
.map(
|
|
62
|
+
(task, index) => `<li>
|
|
63
|
+
<div class="jive-task-head"><span class="jive-task-name">${waiting ? `${index + 1}. ` : ""}${escape(task.name)}</span>
|
|
64
|
+
<span class="jive-task-age">${waiting ? "waiting" : "in it"} ${duration(now - task.enteredAt)}</span></div>
|
|
65
|
+
${task.detail === undefined ? "" : `<div class="jive-task-note">${escape(task.detail)}</div>`}
|
|
66
|
+
<div class="jive-task-note">${noteOf(task.lastNote)}</div>
|
|
67
|
+
</li>`,
|
|
68
|
+
)
|
|
69
|
+
.join("")
|
|
70
|
+
const more = place.total - place.tasks.length
|
|
71
|
+
return `<ol class="jive-tasks">${rows}</ol>${more > 0 ? `<p class="jive-more">and ${number(more)} more, in queue order</p>` : ""}`
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const statsBlock = (stats: StepStats): string => {
|
|
75
|
+
const ended =
|
|
76
|
+
stats.endStates.length === 0
|
|
77
|
+
? "<li>none yet</li>"
|
|
78
|
+
: stats.endStates.map((end) => `<li>${escape(end.end)}: ${number(end.runs)} ${end.runs === 1 ? "run" : "runs"}</li>`).join("")
|
|
79
|
+
const tokens =
|
|
80
|
+
stats.tokens === null
|
|
81
|
+
? "none (no agent)"
|
|
82
|
+
: `${millions(stats.tokens.input + stats.tokens.output)} tokens (${millions(stats.tokens.input)} in, ${millions(stats.tokens.output)} out)`
|
|
83
|
+
const notes = (stats.notes ?? []).map((note) => `<p class="jive-sub">${escape(note)}</p>`).join("")
|
|
84
|
+
return `<h3>Stats, ${escape(stats.over)}</h3>
|
|
85
|
+
<dl class="jive-stats">
|
|
86
|
+
<dt>Calls</dt><dd>${number(stats.calls)}</dd>
|
|
87
|
+
<dt>Token spend</dt><dd>${tokens}</dd>
|
|
88
|
+
<dt>Time per task</dt><dd>median ${duration(stats.timePerTaskMs.median)}, 90th percentile ${duration(stats.timePerTaskMs.p90)}</dd>
|
|
89
|
+
<dt>Ended as</dt><dd><ul class="jive-ends">${ended}</ul></dd>
|
|
90
|
+
</dl>${notes}`
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** The latest finished runs of a step, newest first: each with its task, try, end state, agent, tokens, cost and a link to each transcript. */
|
|
94
|
+
const runsBlock = (input: StepRuns, now: number): string => {
|
|
95
|
+
if (input.runs.length === 0) return `<h3>Latest finished runs</h3><p class="jive-empty">No finished run yet. ${escape(input.from)}</p>`
|
|
96
|
+
const rows = input.runs
|
|
97
|
+
.map((run) => {
|
|
98
|
+
const ended = run.error !== null ? `failed: ${escape(run.error)}` : run.endState === null ? "ended with no end state" : `ended "${escape(run.endState)}"`
|
|
99
|
+
const spent = run.tokens === null ? "no agent, so no tokens or cost" : `${millions(run.tokens)} tokens, ${run.costUsd === null ? "cost not recorded" : dollars(run.costUsd)}`
|
|
100
|
+
const links =
|
|
101
|
+
run.transcripts.length === 0
|
|
102
|
+
? "No transcript"
|
|
103
|
+
: run.transcripts
|
|
104
|
+
.map((file, index) => {
|
|
105
|
+
const label = `transcript${run.transcripts.length === 1 ? "" : ` ${index + 1}`} (${escape(file.name)})`
|
|
106
|
+
return file.href === null ? `${label[0]!.toUpperCase()}${label.slice(1)}: not reachable from this page` : `<a href="${escape(file.href)}" target="_blank" rel="noopener">Open ${label}</a>`
|
|
107
|
+
})
|
|
108
|
+
.join(" · ")
|
|
109
|
+
return `<li>
|
|
110
|
+
<div class="jive-task-head"><span class="jive-task-name">${escape(run.taskName)}, try ${number(run.call)}</span>
|
|
111
|
+
<span class="jive-task-age">${duration(now - run.endedAt)} ago</span></div>
|
|
112
|
+
<div>${ended}; agent: ${run.agent === null ? "not recorded" : escape(run.agent)}; ${spent}</div>
|
|
113
|
+
<div>${links}</div>
|
|
114
|
+
</li>`
|
|
115
|
+
})
|
|
116
|
+
.join("")
|
|
117
|
+
return `<h3>Latest finished runs</h3><p class="jive-sub">${escape(input.from)}</p><ul class="jive-runs">${rows}</ul>`
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const extraLines = (lines: ReadonlyArray<string> | undefined): string => (lines ?? []).map((line) => `<p class="jive-sub">${escape(line)}</p>`).join("")
|
|
121
|
+
|
|
122
|
+
/** `extra`: more lines in words under the heading, such as the step's access, or where a sub-workflow step's tasks are inside it. */
|
|
123
|
+
export const stepPanel = (input: {
|
|
124
|
+
readonly name: string
|
|
125
|
+
readonly place: PlaceTasks
|
|
126
|
+
readonly stats: StepStats | undefined
|
|
127
|
+
readonly now: number
|
|
128
|
+
readonly extra?: ReadonlyArray<string>
|
|
129
|
+
readonly runs?: StepRuns
|
|
130
|
+
}): string =>
|
|
131
|
+
`<h2>Step: ${escape(input.name)}</h2>
|
|
132
|
+
<h3>${number(input.place.total)} ${input.place.total === 1 ? "task" : "tasks"} in this step</h3>
|
|
133
|
+
${extraLines(input.extra)}
|
|
134
|
+
${taskList(input.place, input.now, false)}
|
|
135
|
+
${input.stats === undefined ? '<p class="jive-empty">No stats recorded for this step yet.</p>' : statsBlock(input.stats)}
|
|
136
|
+
${input.runs === undefined ? "" : runsBlock(input.runs, input.now)}`
|
|
137
|
+
|
|
138
|
+
/** `extra`: more lines in words under the heading, such as which queues of the platform the drawn line carries. */
|
|
139
|
+
export const linePanel = (input: { readonly into: string; readonly from: string; readonly place: PlaceTasks; readonly now: number; readonly extra?: ReadonlyArray<string> }): string =>
|
|
140
|
+
`<h2>Queue into ${escape(input.into)}</h2>
|
|
141
|
+
<p class="jive-sub">The line from ${escape(input.from)}</p>
|
|
142
|
+
${extraLines(input.extra)}
|
|
143
|
+
<h3>${number(input.place.total)} ${input.place.total === 1 ? "task" : "tasks"} waiting, oldest first</h3>
|
|
144
|
+
${taskList(input.place, input.now, true)}`
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { pieHtml, type PieSlice, topSlices } from "./pie"
|
|
3
|
+
|
|
4
|
+
const slice = (step: string, value: number): PieSlice => ({ step, label: step, value, words: `${value} tasks` })
|
|
5
|
+
|
|
6
|
+
describe("the pie of a metric across steps", () => {
|
|
7
|
+
test("keeps the six largest steps and adds up the rest as other steps", () => {
|
|
8
|
+
const slices = topSlices({ slices: [1, 2, 3, 4, 5, 6, 7, 8].map((n) => slice(`s${n}`, n)), wordsOf: (n) => `${n} tasks` })
|
|
9
|
+
expect(slices.map((each) => each.label)).toEqual(["s8", "s7", "s6", "s5", "s4", "s3", "other steps"])
|
|
10
|
+
expect(slices.at(-1)).toEqual({ label: "other steps", value: 3, words: "3 tasks" })
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
test("drops steps at zero and keeps seven steps whole rather than folding one", () => {
|
|
14
|
+
const slices = topSlices({ slices: [0, 1, 2, 3, 4, 5, 6, 7].map((n) => slice(`s${n}`, n)), wordsOf: String })
|
|
15
|
+
expect(slices).toHaveLength(7)
|
|
16
|
+
expect(slices.some((each) => each.label === "other steps")).toBe(false)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test("names every slice with its value and share in the list, and a tiny share reads as under 1%", () => {
|
|
20
|
+
const html = pieHtml({ title: "Tasks", slices: [slice("big", 990), slice("tiny", 1)], dark: true, empty: "none" })
|
|
21
|
+
expect(html).toContain("990 tasks, 100%")
|
|
22
|
+
expect(html).toContain("1 tasks, under 1%")
|
|
23
|
+
// A slice too thin to label on the pie still has its name in the list, and a click target.
|
|
24
|
+
expect(html).toContain('data-step="tiny"')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
test("labels only slices of 8% or more on the pie itself", () => {
|
|
28
|
+
const html = pieHtml({ title: "Tasks", slices: [slice("big", 95), slice("small", 5)], dark: false, empty: "none" })
|
|
29
|
+
const onPie = html.slice(0, html.indexOf("<ul"))
|
|
30
|
+
expect(onPie).toContain(">big</text>")
|
|
31
|
+
expect(onPie).not.toContain(">small</text>")
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
test("says why it is empty, and escapes names", () => {
|
|
35
|
+
expect(pieHtml({ title: "Cost", slices: [], dark: true, empty: "Nothing spent yet." })).toContain("Nothing spent yet.")
|
|
36
|
+
expect(pieHtml({ title: "T", slices: [{ step: "a", label: "<b>", value: 1, words: "1" }], dark: true, empty: "" })).toContain("<b>")
|
|
37
|
+
})
|
|
38
|
+
})
|
package/dashboard/pie.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// The pie beside the task list: the selected metric split across a workflow's steps. Every slice of 8% or more is
|
|
2
|
+
// labelled on the pie with its step's name and value in words, and the list under it names every slice with its value
|
|
3
|
+
// and share, so no slice is told apart by
|
|
4
|
+
// colour alone. At most six steps get their own slice; the rest are added up as "other steps".
|
|
5
|
+
|
|
6
|
+
export interface PieSlice {
|
|
7
|
+
/** The step's jive:export; clicking its slice opens its panel. Absent for "other steps". */
|
|
8
|
+
readonly step?: string;
|
|
9
|
+
readonly label: string;
|
|
10
|
+
readonly value: number;
|
|
11
|
+
/** The value in words with its unit, as the badges write it. */
|
|
12
|
+
readonly words: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** The reference palette's categorical slots 1 to 6, stepped for the dark and the light surface, and a gray for "other steps". */
|
|
16
|
+
const SLOTS = {
|
|
17
|
+
dark: ['#3987e5', '#d95926', '#199e70', '#c98500', '#d55181', '#0ca30c'],
|
|
18
|
+
light: ['#2a78d6', '#eb6834', '#1baf7a', '#eda100', '#e87ba4', '#008300'],
|
|
19
|
+
} as const;
|
|
20
|
+
const OTHER = { dark: '#8a8f8b', light: '#9a9c98' } as const;
|
|
21
|
+
const MOST_SLICES = 6;
|
|
22
|
+
/** A slice this share of the whole or larger is labelled on the pie; every slice is named in the list under it. */
|
|
23
|
+
const LABELLED_SHARE = 0.08;
|
|
24
|
+
|
|
25
|
+
/** "52%", or "under 1%" for a share that rounds to nothing. */
|
|
26
|
+
const percent = (share: number): string => (share > 0 && share < 0.005 ? "under 1%" : `${Math.round(share * 100)}%`);
|
|
27
|
+
|
|
28
|
+
const escape = (text: string): string =>
|
|
29
|
+
text.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>').replaceAll('"', '"');
|
|
30
|
+
|
|
31
|
+
/** The six largest steps, then the rest added up, with the words `wordsOf` gives a total. */
|
|
32
|
+
export const topSlices = (input: { readonly slices: ReadonlyArray<PieSlice>; readonly wordsOf: (value: number) => string }): ReadonlyArray<PieSlice> => {
|
|
33
|
+
const sorted = [...input.slices].filter((slice) => slice.value > 0).sort((a, b) => b.value - a.value);
|
|
34
|
+
if (sorted.length <= MOST_SLICES + 1) return sorted;
|
|
35
|
+
const rest = sorted.slice(MOST_SLICES).reduce((total, slice) => total + slice.value, 0);
|
|
36
|
+
return [...sorted.slice(0, MOST_SLICES), { label: 'other steps', value: rest, words: input.wordsOf(rest) }];
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const point = (input: { readonly angle: number; readonly radius: number }) => ({
|
|
40
|
+
x: 230 + input.radius * Math.sin(input.angle),
|
|
41
|
+
y: 130 - input.radius * Math.cos(input.angle),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/** The pie's HTML: a heading, the SVG with a label per slice, and the list of values and shares. */
|
|
45
|
+
export const pieHtml = (input: { readonly title: string; readonly slices: ReadonlyArray<PieSlice>; readonly dark: boolean; readonly empty: string }): string => {
|
|
46
|
+
const total = input.slices.reduce((sum, slice) => sum + slice.value, 0);
|
|
47
|
+
if (total === 0) return `<h3>${escape(input.title)}</h3><p class="jive-empty">${escape(input.empty)}</p>`;
|
|
48
|
+
const mode = input.dark ? 'dark' : 'light';
|
|
49
|
+
const colourOf = (slice: PieSlice, index: number) => (slice.step === undefined ? OTHER[mode] : SLOTS[mode][index] ?? OTHER[mode]);
|
|
50
|
+
const surface = input.dark ? '#22262a' : '#ffffff';
|
|
51
|
+
const ink = input.dark ? '#e3e7e4' : '#16201a';
|
|
52
|
+
let start = 0;
|
|
53
|
+
const marks = input.slices.map((slice, index) => {
|
|
54
|
+
const sweep = (slice.value / total) * Math.PI * 2;
|
|
55
|
+
const end = start + sweep;
|
|
56
|
+
const middle = start + sweep / 2;
|
|
57
|
+
const from = point({ angle: start, radius: 80 });
|
|
58
|
+
const to = point({ angle: end, radius: 80 });
|
|
59
|
+
const shape =
|
|
60
|
+
input.slices.length === 1
|
|
61
|
+
? `<circle cx="230" cy="130" r="80" fill="${colourOf(slice, index)}" stroke="${surface}" stroke-width="2"/>`
|
|
62
|
+
: `<path d="M 230 130 L ${from.x} ${from.y} A 80 80 0 ${sweep > Math.PI ? 1 : 0} 1 ${to.x} ${to.y} Z" fill="${colourOf(slice, index)}" stroke="${surface}" stroke-width="2"/>`;
|
|
63
|
+
// Each slice's name and value sit outside it, on a short line from its middle, on the side it points to.
|
|
64
|
+
const edge = point({ angle: middle, radius: 82 });
|
|
65
|
+
const elbow = point({ angle: middle, radius: 96 });
|
|
66
|
+
const right = Math.sin(middle) >= 0;
|
|
67
|
+
const textX = elbow.x + (right ? 6 : -6);
|
|
68
|
+
const label = slice.value / total < LABELLED_SHARE ? "" : `<line x1="${edge.x}" y1="${edge.y}" x2="${elbow.x}" y2="${elbow.y}" stroke="${ink}" stroke-width="1"/>
|
|
69
|
+
<text x="${textX}" y="${elbow.y - 2}" text-anchor="${right ? 'start' : 'end'}" fill="${ink}" font-size="11" font-weight="bold">${escape(slice.label)}</text>
|
|
70
|
+
<text x="${textX}" y="${elbow.y + 11}" text-anchor="${right ? 'start' : 'end'}" fill="${ink}" font-size="11">${escape(slice.words)}</text>`;
|
|
71
|
+
start = end;
|
|
72
|
+
const target = slice.step === undefined ? '' : ` data-step="${escape(slice.step)}" class="jive-slice" role="button" tabindex="0"`;
|
|
73
|
+
return `<g${target}><title>${escape(`${slice.label}: ${slice.words}, ${percent(slice.value / total)}`)}</title>${shape}${label}</g>`;
|
|
74
|
+
});
|
|
75
|
+
const rows = input.slices
|
|
76
|
+
.map(
|
|
77
|
+
(slice, index) => `<li${slice.step === undefined ? '' : ` data-step="${escape(slice.step)}" class="jive-slice"`}>
|
|
78
|
+
<span class="jive-swatch" style="background:${colourOf(slice, index)}"></span>
|
|
79
|
+
<span class="jive-slice-name">${escape(slice.label)}</span>
|
|
80
|
+
<span class="jive-slice-value">${escape(slice.words)}, ${percent(slice.value / total)}</span></li>`,
|
|
81
|
+
)
|
|
82
|
+
.join('');
|
|
83
|
+
return `<h3>${escape(input.title)}</h3>
|
|
84
|
+
<svg class="jive-pie" viewBox="0 0 460 260" width="100%" font-family="Arial, sans-serif">${marks.join('')}</svg>
|
|
85
|
+
<ul class="jive-slices">${rows}</ul>`;
|
|
86
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test"
|
|
2
|
+
import { type DiagramShape, platformLinesByFlow, type PlatformGraph } from "./places"
|
|
3
|
+
|
|
4
|
+
/** Builds diagram shapes the way bpmn-js's element registry holds them: each with its outgoing lines and their targets. */
|
|
5
|
+
const diagram = (
|
|
6
|
+
nodes: ReadonlyArray<{ readonly id: string; readonly type: string; readonly attrs?: Readonly<Record<string, string>> }>,
|
|
7
|
+
flows: ReadonlyArray<{ readonly id: string; readonly from: string; readonly to: string; readonly name?: string }>,
|
|
8
|
+
): ReadonlyArray<DiagramShape> => {
|
|
9
|
+
const shapes = new Map(nodes.map((node) => [node.id, { id: node.id, type: node.type, businessObject: { $attrs: node.attrs ?? {} }, outgoing: [] as Array<unknown> }]))
|
|
10
|
+
for (const flow of flows)
|
|
11
|
+
shapes.get(flow.from)!.outgoing.push({ id: flow.id, businessObject: flow.name === undefined ? {} : { name: flow.name }, target: shapes.get(flow.to)! })
|
|
12
|
+
return [...shapes.values()] as unknown as ReadonlyArray<DiagramShape>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Arriving items and retried ones merge in front of Check; Check's decision splits its end states.
|
|
16
|
+
const shapes = diagram(
|
|
17
|
+
[
|
|
18
|
+
{ id: "arrives", type: "bpmn:StartEvent", attrs: { "jive:kind": "task" } },
|
|
19
|
+
{ id: "backInLine", type: "bpmn:ExclusiveGateway" },
|
|
20
|
+
{ id: "check", type: "bpmn:ServiceTask", attrs: { "jive:export": "check" } },
|
|
21
|
+
{ id: "checked", type: "bpmn:ExclusiveGateway", attrs: { "jive:ends": "check" } },
|
|
22
|
+
{ id: "endPassed", type: "bpmn:EndEvent", attrs: { "jive:end": "passed" } },
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
{ id: "toBackInLine", from: "arrives", to: "backInLine" },
|
|
26
|
+
{ id: "toCheck", from: "backInLine", to: "check" },
|
|
27
|
+
{ id: "toChecked", from: "check", to: "checked" },
|
|
28
|
+
{ id: "passed", from: "checked", to: "endPassed", name: "passed" },
|
|
29
|
+
{ id: "again", from: "checked", to: "backInLine", name: "try again" },
|
|
30
|
+
],
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
const graph: PlatformGraph = {
|
|
34
|
+
events: [{ id: "task", kind: "task" }],
|
|
35
|
+
lines: [
|
|
36
|
+
{ id: "event.task>step.check", from: { event: "task" }, to: { step: "check" } },
|
|
37
|
+
{ id: "step.check.try again>step.check", from: { step: "check", endState: "try again" }, to: { step: "check" } },
|
|
38
|
+
{ id: "step.check.passed>end.passed", from: { step: "check", endState: "passed" }, to: { end: "passed" } },
|
|
39
|
+
],
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe("which platform lines each drawn line carries", () => {
|
|
43
|
+
test("the line out of a merge carries every platform line that passes through it", () => {
|
|
44
|
+
const { byFlow, undrawn } = platformLinesByFlow({ shapes, graph })
|
|
45
|
+
expect(undrawn).toEqual([])
|
|
46
|
+
expect(byFlow.get("toCheck")?.map((line) => line.id)).toEqual(["event.task>step.check", "step.check.try again>step.check"])
|
|
47
|
+
expect(byFlow.get("toBackInLine")?.map((line) => line.id)).toEqual(["event.task>step.check"])
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
test("at a decision, a platform line takes only the drawn line named by its end state", () => {
|
|
51
|
+
const { byFlow } = platformLinesByFlow({ shapes, graph })
|
|
52
|
+
expect(byFlow.get("again")?.map((line) => line.id)).toEqual(["step.check.try again>step.check"])
|
|
53
|
+
expect(byFlow.get("passed")?.map((line) => line.id)).toEqual(["step.check.passed>end.passed"])
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test("a platform line the diagram has no path for is reported as undrawn", () => {
|
|
57
|
+
const extra: PlatformGraph = { ...graph, lines: [...graph.lines, { id: "step.check.failed>end.failed", from: { step: "check", endState: "failed" }, to: { end: "failed" } }] }
|
|
58
|
+
expect(platformLinesByFlow({ shapes, graph: extra }).undrawn).toEqual(["step.check.failed>end.failed"])
|
|
59
|
+
})
|
|
60
|
+
})
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// Which of the platform's queues each line of a BPMN workflow diagram draws. The compiler turns the diagram into
|
|
2
|
+
// platform lines from an event or a step's end state to a step or an end state, passing through gateways: a merge
|
|
3
|
+
// diamond only joins lines, and a decision splits a step's end states by the names of its lines. So one drawn line can
|
|
4
|
+
// carry several platform lines (the line out of the merge in front of Decompile carries both the arriving functions
|
|
5
|
+
// and the ones that came back from Learn from blocked), and one platform line can be drawn as several lines.
|
|
6
|
+
//
|
|
7
|
+
// The platform lines come from the workflow's registered graph; each is found in the diagram by walking from its
|
|
8
|
+
// source element to its target element, taking at a decision only the line named by its end state.
|
|
9
|
+
|
|
10
|
+
/** The parts of @jive-sh/workflow-platform's graph this needs: its events, and its lines with their ids. */
|
|
11
|
+
export interface PlatformGraph {
|
|
12
|
+
readonly events: ReadonlyArray<{ readonly id: string; readonly kind: string; readonly field?: string }>;
|
|
13
|
+
readonly lines: ReadonlyArray<PlatformLine>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface PlatformLine {
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly from: { readonly event: string } | { readonly step: string; readonly endState: string } | { readonly end: string };
|
|
19
|
+
readonly to: { readonly step: string } | { readonly end: string };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** A diagram element as bpmn-js's element registry holds it, with only what the walk reads. */
|
|
23
|
+
export interface DiagramShape {
|
|
24
|
+
readonly id: string;
|
|
25
|
+
readonly type: string;
|
|
26
|
+
readonly businessObject: { readonly name?: string; readonly $attrs?: Readonly<Record<string, string>> };
|
|
27
|
+
readonly outgoing?: ReadonlyArray<{ readonly id: string; readonly businessObject: { readonly name?: string }; readonly target: DiagramShape }>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const attribute = (shape: DiagramShape, name: string): string | undefined => shape.businessObject.$attrs?.[`jive:${name}`];
|
|
31
|
+
|
|
32
|
+
const isGateway = (shape: DiagramShape) => shape.type === 'bpmn:ExclusiveGateway';
|
|
33
|
+
|
|
34
|
+
/** The start event a platform event is drawn as: the one whose jive:kind (and jive:field, for a change) matches. */
|
|
35
|
+
const startEventOf = (shapes: ReadonlyArray<DiagramShape>, event: PlatformGraph['events'][number]) =>
|
|
36
|
+
shapes.find(
|
|
37
|
+
(shape) => shape.type === 'bpmn:StartEvent' && attribute(shape, 'kind') === event.kind && (event.kind !== 'change' || attribute(shape, 'field') === event.field),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
/** The drawn lines from `start` to the element `isTarget` matches, through gateways; at a decision only the line named `endState`. */
|
|
41
|
+
const pathTo = (input: { readonly start: DiagramShape; readonly endState: string | undefined; readonly isTarget: (shape: DiagramShape) => boolean }): ReadonlyArray<string> | undefined => {
|
|
42
|
+
const walk = (shape: DiagramShape, seen: ReadonlySet<string>): ReadonlyArray<string> | undefined => {
|
|
43
|
+
for (const flow of shape.outgoing ?? []) {
|
|
44
|
+
const deciding = isGateway(shape) && attribute(shape, 'ends') !== undefined;
|
|
45
|
+
if (deciding && flow.businessObject.name !== input.endState) continue;
|
|
46
|
+
if (input.isTarget(flow.target)) return [flow.id];
|
|
47
|
+
if (isGateway(flow.target) && !seen.has(flow.target.id)) {
|
|
48
|
+
const rest = walk(flow.target, new Set([...seen, flow.target.id]));
|
|
49
|
+
if (rest !== undefined) return [flow.id, ...rest];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
};
|
|
54
|
+
return walk(input.start, new Set());
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** For each drawn line (by its BPMN id), the platform lines it carries; `undrawn` lists the platform lines the diagram has no path for. */
|
|
58
|
+
export const platformLinesByFlow = (input: {
|
|
59
|
+
readonly shapes: ReadonlyArray<DiagramShape>;
|
|
60
|
+
readonly graph: PlatformGraph;
|
|
61
|
+
}): { readonly byFlow: ReadonlyMap<string, ReadonlyArray<PlatformLine>>; readonly undrawn: ReadonlyArray<string> } => {
|
|
62
|
+
const undrawn: Array<string> = [];
|
|
63
|
+
const byFlow = new Map<string, Array<PlatformLine>>();
|
|
64
|
+
const stepShape = (step: string) => input.shapes.find((shape) => attribute(shape, 'export') === step && shape.type !== 'bpmn:Process');
|
|
65
|
+
const endShape = (end: string) => input.shapes.find((shape) => shape.type === 'bpmn:EndEvent' && attribute(shape, 'end') === end);
|
|
66
|
+
for (const line of input.graph.lines) {
|
|
67
|
+
const from = line.from;
|
|
68
|
+
const start =
|
|
69
|
+
'event' in from
|
|
70
|
+
? (() => {
|
|
71
|
+
const event = input.graph.events.find((candidate) => candidate.id === from.event);
|
|
72
|
+
return event === undefined ? undefined : startEventOf(input.shapes, event);
|
|
73
|
+
})()
|
|
74
|
+
: 'step' in from
|
|
75
|
+
? stepShape(from.step)
|
|
76
|
+
: endShape(from.end);
|
|
77
|
+
const to = line.to;
|
|
78
|
+
const target = 'step' in to ? stepShape(to.step) : endShape(to.end);
|
|
79
|
+
const path =
|
|
80
|
+
start === undefined || target === undefined ? undefined : pathTo({ start, endState: 'step' in from ? from.endState : undefined, isTarget: (shape) => shape.id === target.id });
|
|
81
|
+
if (path === undefined) undrawn.push(line.id);
|
|
82
|
+
for (const flow of path ?? []) byFlow.set(flow, [...(byFlow.get(flow) ?? []), line]);
|
|
83
|
+
}
|
|
84
|
+
return { byFlow, undrawn };
|
|
85
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// What each BPMN element is drawn as in the activity-diagram look, and its size. Shared by the ELK layout (which sizes
|
|
2
|
+
// the boxes) and the renderer (which draws them), so the two never disagree.
|
|
3
|
+
|
|
4
|
+
export type NodeKind = 'event' | 'decision' | 'merge' | 'step';
|
|
5
|
+
|
|
6
|
+
export interface NodeShape {
|
|
7
|
+
readonly kind: NodeKind;
|
|
8
|
+
readonly width: number;
|
|
9
|
+
readonly height: number;
|
|
10
|
+
/** The width of the name drawn beside the shape (events and decisions), or null when it has none or it is inside. */
|
|
11
|
+
readonly labelBeside: number | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
interface ShapeSource {
|
|
15
|
+
readonly $type: string;
|
|
16
|
+
readonly name?: string;
|
|
17
|
+
readonly incoming?: ReadonlyArray<unknown>;
|
|
18
|
+
readonly outgoing?: ReadonlyArray<unknown>;
|
|
19
|
+
readonly loopCharacteristics?: unknown;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** An estimate of Arial's width, enough to size boxes: ELK needs sizes before any page measures text. */
|
|
23
|
+
export const textWidth = (text: string, fontSize = 12): number => Math.ceil(text.length * fontSize * 0.56);
|
|
24
|
+
|
|
25
|
+
/** A gateway where branches rejoin: several lines in, one out. It asks no question, so it is a plain diamond with no label. */
|
|
26
|
+
export const isMerge = (element: ShapeSource): boolean =>
|
|
27
|
+
element.$type === 'bpmn:ExclusiveGateway' && (element.incoming?.length ?? 0) > 1 && (element.outgoing?.length ?? 0) === 1;
|
|
28
|
+
|
|
29
|
+
export const nodeShape = (element: ShapeSource): NodeShape => {
|
|
30
|
+
const name = element.name ?? '';
|
|
31
|
+
if (element.$type.endsWith('Event'))
|
|
32
|
+
return { kind: 'event', width: 30, height: 30, labelBeside: name === '' ? null : textWidth(name) };
|
|
33
|
+
if (element.$type === 'bpmn:ExclusiveGateway')
|
|
34
|
+
return isMerge(element)
|
|
35
|
+
? { kind: 'merge', width: 26, height: 26, labelBeside: null }
|
|
36
|
+
: { kind: 'decision', width: 34, height: 34, labelBeside: name === '' ? null : textWidth(name) };
|
|
37
|
+
const tall = element.$type === 'bpmn:CallActivity' || element.loopCharacteristics !== undefined;
|
|
38
|
+
return { kind: 'step', width: Math.max(120, textWidth(name) + 56), height: tall ? 62 : 48, labelBeside: null };
|
|
39
|
+
};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// Draws a laid-out BPMN workflow with bpmn-js in the activity-diagram look, puts the selected metric's words on the
|
|
2
|
+
// diagram as badges (diagram-js overlays), and opens a panel when a step, a line or a badge is clicked.
|
|
3
|
+
import NavigatedViewer from "bpmn-js/lib/NavigatedViewer"
|
|
4
|
+
import { activityLookModule } from "./activity-look"
|
|
5
|
+
import type { Badges } from "./figures"
|
|
6
|
+
|
|
7
|
+
interface DiagramElement {
|
|
8
|
+
readonly id: string
|
|
9
|
+
readonly type: string
|
|
10
|
+
readonly x: number
|
|
11
|
+
readonly y: number
|
|
12
|
+
readonly width: number
|
|
13
|
+
readonly height: number
|
|
14
|
+
readonly labelTarget?: unknown
|
|
15
|
+
readonly label?: { readonly x: number; readonly width: number }
|
|
16
|
+
readonly incoming: ReadonlyArray<{ readonly id: string; readonly waypoints: ReadonlyArray<{ readonly x: number; readonly y: number }> }>
|
|
17
|
+
readonly outgoing?: ReadonlyArray<unknown>
|
|
18
|
+
readonly waypoints?: ReadonlyArray<unknown>
|
|
19
|
+
readonly source?: { readonly businessObject: { readonly name?: string } }
|
|
20
|
+
readonly target?: { readonly businessObject: { readonly name?: string } }
|
|
21
|
+
readonly businessObject: { readonly name?: string; readonly $attrs?: Readonly<Record<string, string>> }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const jiveAttribute = (element: DiagramElement, name: string): string | undefined => element.businessObject?.$attrs?.[`jive:${name}`]
|
|
25
|
+
|
|
26
|
+
/** Room around the fitted diagram, in diagram units. */
|
|
27
|
+
const VIEW_MARGIN = 40
|
|
28
|
+
|
|
29
|
+
/** The overlay type of the badges, so a new set replaces the old. */
|
|
30
|
+
const BADGE_OVERLAY = "jive-badge"
|
|
31
|
+
|
|
32
|
+
/** A badge. Clicking it opens the panel of the element it describes (`forElement`): a line or a step. */
|
|
33
|
+
const badge = (words: string, forElement: string): string => {
|
|
34
|
+
const node = document.createElement("div")
|
|
35
|
+
node.className = "jive-badge"
|
|
36
|
+
node.dataset["element"] = forElement
|
|
37
|
+
node.textContent = words
|
|
38
|
+
return node.outerHTML
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
type Overlays = { add: (id: string, type: string, overlay: unknown) => void; remove: (filter: { type: string }) => void }
|
|
42
|
+
|
|
43
|
+
/** Puts each step's words right of its box, its queue's words on the line into it, and each end state's after its name. */
|
|
44
|
+
const addBadgeOverlays = (overlays: Overlays, elements: ReadonlyArray<DiagramElement>, badges: Badges) => {
|
|
45
|
+
for (const element of elements) {
|
|
46
|
+
if (element.labelTarget !== undefined || element.type === "bpmn:Process") continue
|
|
47
|
+
const step = jiveAttribute(element, "export")
|
|
48
|
+
const onStep = step === undefined ? undefined : badges.steps[step]
|
|
49
|
+
// To the right of the box, level with its middle, clear of the queue badge on the line above.
|
|
50
|
+
if (onStep !== undefined) overlays.add(element.id, BADGE_OVERLAY, { position: { top: element.height / 2 - 10, left: element.width + 8 }, html: badge(onStep, element.id) })
|
|
51
|
+
const onQueue = step === undefined ? undefined : badges.queues[step]
|
|
52
|
+
const line = element.incoming[0]
|
|
53
|
+
if (onQueue !== undefined && line !== undefined && line.waypoints.length >= 2) {
|
|
54
|
+
const xs = line.waypoints.map((point) => point.x)
|
|
55
|
+
const ys = line.waypoints.map((point) => point.y)
|
|
56
|
+
const last = line.waypoints[line.waypoints.length - 1]!
|
|
57
|
+
const beforeLast = line.waypoints[line.waypoints.length - 2]!
|
|
58
|
+
const middle = { x: (last.x + beforeLast.x) / 2, y: (last.y + beforeLast.y) / 2 }
|
|
59
|
+
// Beside a vertical line, on a horizontal one.
|
|
60
|
+
const placement = last.x === beforeLast.x ? "jive-beside-line" : "jive-on-line"
|
|
61
|
+
overlays.add(line.id, BADGE_OVERLAY, {
|
|
62
|
+
position: { left: middle.x - Math.min(...xs), top: middle.y - Math.min(...ys) },
|
|
63
|
+
html: `<div class="${placement}">${badge(onQueue, line.id)}</div>`,
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
const end = jiveAttribute(element, "end")
|
|
67
|
+
const onEnd = end === undefined ? undefined : badges.ends[end]
|
|
68
|
+
if (onEnd !== undefined) {
|
|
69
|
+
// After the end state's name when it is beside the circle; above the circle's right otherwise.
|
|
70
|
+
const label = element.label
|
|
71
|
+
const besideName = label !== undefined && label.x > element.x + element.width
|
|
72
|
+
overlays.add(element.id, BADGE_OVERLAY, {
|
|
73
|
+
position: besideName ? { top: element.height / 2 - 10, left: label.x + label.width - element.x + 8 } : { top: -12, left: element.width + 2 },
|
|
74
|
+
html: badge(onEnd, element.id),
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Where the panel's contents come from. Each method returns the panel's HTML for one clicked step or line. */
|
|
81
|
+
export interface PanelSource {
|
|
82
|
+
/** A step, by its id (the BPMN element's jive:export) and its drawn name. */
|
|
83
|
+
readonly step: (input: { readonly step: string; readonly name: string }) => Promise<string>
|
|
84
|
+
/** A drawn line, by its BPMN id; `into` and `from` are the names of the elements it joins. */
|
|
85
|
+
readonly line: (input: { readonly flowId: string; readonly into: string; readonly from: string }) => Promise<string>
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** A drawn workflow: its elements, and how to show new badges, open a step's panel and re-read the open panel. */
|
|
89
|
+
export interface DrawnWorkflow {
|
|
90
|
+
/** The diagram's elements as bpmn-js holds them, for matching them to the workflow's graph. */
|
|
91
|
+
readonly elements: () => ReadonlyArray<DiagramElement>
|
|
92
|
+
readonly importWarnings: ReadonlyArray<string>
|
|
93
|
+
readonly setBadges: (badges: Badges) => void
|
|
94
|
+
/** Opens the panel of the step whose id is `step`. */
|
|
95
|
+
readonly openStep: (step: string) => void
|
|
96
|
+
readonly refreshPanel: () => void
|
|
97
|
+
readonly destroy: () => void
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Draws `xml` (already laid out) in `canvas`; clicking a step, line or badge opens its panel in `panel`. */
|
|
101
|
+
export const drawWorkflow = async (input: {
|
|
102
|
+
readonly xml: string
|
|
103
|
+
readonly canvas: HTMLElement
|
|
104
|
+
readonly panel: HTMLElement
|
|
105
|
+
readonly dark: boolean
|
|
106
|
+
readonly source: PanelSource
|
|
107
|
+
}): Promise<DrawnWorkflow> => {
|
|
108
|
+
const bpmnRenderer = input.dark
|
|
109
|
+
? { defaultFillColor: "#22262a", defaultStrokeColor: "#e3e7e4", defaultLabelColor: "#e3e7e4" }
|
|
110
|
+
: { defaultFillColor: "#f1f1f1", defaultStrokeColor: "#181818", defaultLabelColor: "#181818" }
|
|
111
|
+
input.panel.classList.add("jive-panel")
|
|
112
|
+
input.panel.classList.toggle("jive-dark", input.dark)
|
|
113
|
+
input.panel.hidden = true
|
|
114
|
+
const viewer = new NavigatedViewer({ container: input.canvas, bpmnRenderer, additionalModules: [activityLookModule] })
|
|
115
|
+
const imported = await viewer.importXML(input.xml)
|
|
116
|
+
const elementRegistry = viewer.get("elementRegistry") as { getAll: () => ReadonlyArray<DiagramElement>; get: (id: string) => DiagramElement | undefined }
|
|
117
|
+
const overlays = viewer.get("overlays") as Overlays
|
|
118
|
+
const canvas = viewer.get("canvas") as {
|
|
119
|
+
addMarker: (id: string, marker: string) => void
|
|
120
|
+
removeMarker: (id: string, marker: string) => void
|
|
121
|
+
zoom: (level: "fit-viewport") => void
|
|
122
|
+
viewbox: (box?: { x: number; y: number; width: number; height: number }) => { readonly x: number; readonly y: number; readonly width: number; readonly height: number }
|
|
123
|
+
}
|
|
124
|
+
canvas.zoom("fit-viewport")
|
|
125
|
+
// Fitting puts the outermost shapes on the box's edge; a margin keeps the start and end circles and their badges whole.
|
|
126
|
+
const fitted = canvas.viewbox()
|
|
127
|
+
canvas.viewbox({ x: fitted.x - VIEW_MARGIN, y: fitted.y - VIEW_MARGIN, width: fitted.width + 2 * VIEW_MARGIN, height: fitted.height + 2 * VIEW_MARGIN })
|
|
128
|
+
|
|
129
|
+
let selected: DiagramElement | null = null
|
|
130
|
+
const close = () => {
|
|
131
|
+
if (selected !== null) canvas.removeMarker(selected.id, "jive-selected")
|
|
132
|
+
selected = null
|
|
133
|
+
input.panel.hidden = true
|
|
134
|
+
}
|
|
135
|
+
const contentsOf = (element: DiagramElement): Promise<string> | null => {
|
|
136
|
+
if (element.type === "bpmn:SequenceFlow" && element.target !== undefined)
|
|
137
|
+
return input.source.line({
|
|
138
|
+
flowId: element.id,
|
|
139
|
+
into: element.target.businessObject.name ?? "the next element",
|
|
140
|
+
from: element.source?.businessObject.name ?? "the previous element",
|
|
141
|
+
})
|
|
142
|
+
const step = jiveAttribute(element, "export")
|
|
143
|
+
if (step !== undefined && element.type !== "bpmn:Process") return input.source.step({ step, name: element.businessObject.name ?? step })
|
|
144
|
+
return null
|
|
145
|
+
}
|
|
146
|
+
const show = async (element: DiagramElement) => {
|
|
147
|
+
const contents = contentsOf(element)
|
|
148
|
+
if (contents === null) return close()
|
|
149
|
+
const html = await contents.catch((cause) => `<p class="jive-empty">Could not read this from the workflow platform: ${String(cause).replaceAll("<", "<")}</p>`)
|
|
150
|
+
// A later click may have chosen another element while this one was read.
|
|
151
|
+
if (selected?.id !== element.id) return
|
|
152
|
+
input.panel.innerHTML = `<button class="jive-close" aria-label="Close">Close</button>${html}`
|
|
153
|
+
input.panel.querySelector(".jive-close")?.addEventListener("click", close)
|
|
154
|
+
input.panel.hidden = false
|
|
155
|
+
}
|
|
156
|
+
const open = (element: DiagramElement) => {
|
|
157
|
+
if (contentsOf(element) === null) return close()
|
|
158
|
+
if (selected !== null) canvas.removeMarker(selected.id, "jive-selected")
|
|
159
|
+
selected = element
|
|
160
|
+
canvas.addMarker(element.id, "jive-selected")
|
|
161
|
+
void show(element)
|
|
162
|
+
}
|
|
163
|
+
const eventBus = viewer.get("eventBus") as { on: (event: string, callback: (event: { element: DiagramElement }) => void) => void }
|
|
164
|
+
eventBus.on("element.click", ({ element }) => open(element))
|
|
165
|
+
// A badge sits on top of its line or beside its step and opens the same panel.
|
|
166
|
+
const onBadge = (event: Event) => {
|
|
167
|
+
const counted = (event.target as Element | null)?.closest(".jive-badge[data-element]")?.getAttribute("data-element")
|
|
168
|
+
const element = counted === null || counted === undefined ? undefined : elementRegistry.get(counted)
|
|
169
|
+
if (element !== undefined) open(element)
|
|
170
|
+
}
|
|
171
|
+
input.canvas.addEventListener("click", onBadge)
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
elements: () => elementRegistry.getAll(),
|
|
175
|
+
importWarnings: imported.warnings.map((warning) => String(warning)),
|
|
176
|
+
setBadges: (badges) => {
|
|
177
|
+
overlays.remove({ type: BADGE_OVERLAY })
|
|
178
|
+
addBadgeOverlays(overlays, elementRegistry.getAll(), badges)
|
|
179
|
+
},
|
|
180
|
+
openStep: (step) => {
|
|
181
|
+
const element = elementRegistry.getAll().find((candidate) => candidate.type !== "bpmn:Process" && jiveAttribute(candidate, "export") === step)
|
|
182
|
+
if (element !== undefined) open(element)
|
|
183
|
+
},
|
|
184
|
+
refreshPanel: () => {
|
|
185
|
+
if (selected !== null) void show(selected)
|
|
186
|
+
},
|
|
187
|
+
destroy: () => {
|
|
188
|
+
input.canvas.removeEventListener("click", onBadge)
|
|
189
|
+
viewer.destroy()
|
|
190
|
+
},
|
|
191
|
+
}
|
|
192
|
+
}
|