@redvars/peacock 3.5.1 → 3.6.1
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/dist/{BaseButton-DuASuVth.js → BaseButton-BNFAYn-S.js} +2 -2
- package/dist/{BaseButton-DuASuVth.js.map → BaseButton-BNFAYn-S.js.map} +1 -1
- package/dist/BaseInput-14YmcfK7.js +27 -0
- package/dist/BaseInput-14YmcfK7.js.map +1 -0
- package/dist/banner.js +2 -3
- package/dist/banner.js.map +1 -1
- package/dist/{button-DouvOfEU.js → button-colors-Ccys3hvS.js} +5 -294
- package/dist/button-colors-Ccys3hvS.js.map +1 -0
- package/dist/button-group.js +226 -6
- package/dist/button-group.js.map +1 -1
- package/dist/button.js +294 -8
- package/dist/button.js.map +1 -1
- package/dist/calendar-column-view.js +634 -0
- package/dist/calendar-column-view.js.map +1 -0
- package/dist/calendar-event-BrQ_SEKD.js +199 -0
- package/dist/calendar-event-BrQ_SEKD.js.map +1 -0
- package/dist/calendar-month-view.js +376 -0
- package/dist/calendar-month-view.js.map +1 -0
- package/dist/calendar.js +339 -0
- package/dist/calendar.js.map +1 -0
- package/dist/canvas.js +361 -0
- package/dist/canvas.js.map +1 -0
- package/dist/cb-compound-expression.js +125 -0
- package/dist/cb-compound-expression.js.map +1 -0
- package/dist/cb-divider.js +150 -0
- package/dist/cb-divider.js.map +1 -0
- package/dist/cb-expression.js +75 -0
- package/dist/cb-expression.js.map +1 -0
- package/dist/cb-predicate.js +137 -0
- package/dist/cb-predicate.js.map +1 -0
- package/dist/code-editor.js +2 -1
- package/dist/code-editor.js.map +1 -1
- package/dist/code-highlighter.js +1 -1
- package/dist/code-highlighter.js.map +1 -1
- package/dist/condition-builder.js +58 -0
- package/dist/condition-builder.js.map +1 -0
- package/dist/custom-elements-jsdocs.json +8479 -3965
- package/dist/custom-elements.json +15228 -7544
- package/dist/dropdown-button.js +216 -0
- package/dist/dropdown-button.js.map +1 -0
- package/dist/event-manager-D-QCmUgR.js +113 -0
- package/dist/event-manager-D-QCmUgR.js.map +1 -0
- package/dist/fab.js +1 -1
- package/dist/flow-designer-DvTUrDp5.js +1656 -0
- package/dist/flow-designer-DvTUrDp5.js.map +1 -0
- package/dist/flow-designer-node-BWrPuxAR.js +548 -0
- package/dist/flow-designer-node-BWrPuxAR.js.map +1 -0
- package/dist/flow-designer-node.js +4 -0
- package/dist/flow-designer-node.js.map +1 -0
- package/dist/flow-designer.js +16 -0
- package/dist/flow-designer.js.map +1 -0
- package/dist/html-editor.js +27516 -0
- package/dist/html-editor.js.map +1 -0
- package/dist/icon-button-CK1ZuE-2.js +247 -0
- package/dist/icon-button-CK1ZuE-2.js.map +1 -0
- package/dist/index.js +29 -6
- package/dist/index.js.map +1 -1
- package/dist/{is-dark-mode-DicqGkCJ.js → is-dark-mode-DOcaw4Yq.js} +2 -27
- package/dist/is-dark-mode-DOcaw4Yq.js.map +1 -0
- package/dist/modal.js +412 -0
- package/dist/modal.js.map +1 -0
- package/dist/{navigation-rail-Lxetd5-Z.js → navigation-rail-DTTkqohi.js} +1049 -2391
- package/dist/navigation-rail-DTTkqohi.js.map +1 -0
- package/dist/notification-manager.js +268 -0
- package/dist/notification-manager.js.map +1 -0
- package/dist/peacock-loader.js +93 -8
- package/dist/peacock-loader.js.map +1 -1
- package/dist/popover-NC7b1lTq.js +1971 -0
- package/dist/popover-NC7b1lTq.js.map +1 -0
- package/dist/popover-content.js +125 -0
- package/dist/popover-content.js.map +1 -0
- package/dist/popover.js +4 -0
- package/dist/popover.js.map +1 -0
- package/dist/split-button.js +388 -0
- package/dist/split-button.js.map +1 -0
- package/dist/src/__controllers/floating-controller.d.ts +35 -0
- package/dist/src/calendar/base-event.d.ts +10 -0
- package/dist/src/calendar/calendar-column-view.d.ts +41 -0
- package/dist/src/calendar/calendar-event.d.ts +7 -0
- package/dist/src/calendar/calendar-month-view.d.ts +31 -0
- package/dist/src/calendar/calendar.d.ts +65 -0
- package/dist/src/calendar/event-manager.d.ts +17 -0
- package/dist/src/calendar/index.d.ts +4 -0
- package/dist/src/calendar/types.d.ts +13 -0
- package/dist/src/calendar/utils.d.ts +31 -0
- package/dist/src/canvas/canvas.d.ts +92 -0
- package/dist/src/canvas/index.d.ts +2 -0
- package/dist/src/condition-builder/cb-compound-expression.d.ts +31 -0
- package/dist/src/condition-builder/cb-divider.d.ts +26 -0
- package/dist/src/condition-builder/cb-expression.d.ts +31 -0
- package/dist/src/condition-builder/cb-predicate.d.ts +30 -0
- package/dist/src/condition-builder/condition-builder.d.ts +27 -0
- package/dist/src/condition-builder/index.d.ts +5 -0
- package/dist/src/dropdown-button/dropdown-button.d.ts +68 -0
- package/dist/src/dropdown-button/index.d.ts +1 -0
- package/dist/src/flow-designer/commands.d.ts +66 -0
- package/dist/src/flow-designer/flow-designer-node.d.ts +46 -0
- package/dist/src/flow-designer/flow-designer.d.ts +133 -0
- package/dist/src/flow-designer/index.d.ts +7 -0
- package/dist/src/flow-designer/layout.d.ts +30 -0
- package/dist/src/flow-designer/types.d.ts +142 -0
- package/dist/src/flow-designer/validation.d.ts +43 -0
- package/dist/src/flow-designer/workflow-utils.d.ts +40 -0
- package/dist/src/html-editor/html-editor.d.ts +89 -0
- package/dist/src/html-editor/index.d.ts +2 -0
- package/dist/src/index.d.ts +15 -0
- package/dist/src/list/index.d.ts +2 -0
- package/dist/src/list/list-item.d.ts +35 -0
- package/dist/src/list/list.d.ts +28 -0
- package/dist/src/menu/menu/menu.d.ts +5 -7
- package/dist/src/menu/menu-item/menu-item.d.ts +14 -13
- package/dist/src/modal/index.d.ts +1 -0
- package/dist/src/modal/modal.d.ts +57 -0
- package/dist/src/navigation-rail/navigation-rail.d.ts +3 -7
- package/dist/src/notification-manager/index.d.ts +1 -0
- package/dist/src/notification-manager/notification-manager.d.ts +44 -0
- package/dist/src/number-field/number-field.d.ts +2 -2
- package/dist/src/popover/index.d.ts +2 -0
- package/dist/src/popover/popover-content.d.ts +29 -0
- package/dist/src/popover/popover.d.ts +62 -0
- package/dist/src/split-button/index.d.ts +1 -0
- package/dist/src/split-button/split-button.d.ts +72 -0
- package/dist/src/svg/index.d.ts +1 -0
- package/dist/src/svg/svg.d.ts +38 -0
- package/dist/src/toolbar/toolbar.d.ts +3 -3
- package/dist/src/tooltip/tooltip.d.ts +2 -15
- package/dist/test/flow-designer.test.d.ts +1 -0
- package/dist/toolbar.js +3 -3
- package/dist/toolbar.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +10 -2
- package/readme.md +3 -3
- package/src/__controllers/floating-controller.ts +237 -0
- package/src/banner/banner.scss +2 -3
- package/src/button/button/button.ts +1 -0
- package/src/calendar/base-event.ts +49 -0
- package/src/calendar/calendar-column-view.scss +326 -0
- package/src/calendar/calendar-column-view.ts +392 -0
- package/src/calendar/calendar-event.ts +20 -0
- package/src/calendar/calendar-month-view.scss +192 -0
- package/src/calendar/calendar-month-view.ts +244 -0
- package/src/calendar/calendar.scss +71 -0
- package/src/calendar/calendar.ts +298 -0
- package/src/calendar/event-manager.ts +117 -0
- package/src/calendar/index.ts +4 -0
- package/src/calendar/types.ts +14 -0
- package/src/calendar/utils.ts +180 -0
- package/src/canvas/canvas.scss +60 -0
- package/src/canvas/canvas.ts +391 -0
- package/src/canvas/index.ts +2 -0
- package/src/code-highlighter/code-highlighter.ts +1 -1
- package/src/condition-builder/cb-compound-expression.scss +37 -0
- package/src/condition-builder/cb-compound-expression.ts +80 -0
- package/src/condition-builder/cb-divider.scss +93 -0
- package/src/condition-builder/cb-divider.ts +56 -0
- package/src/condition-builder/cb-expression.scss +14 -0
- package/src/condition-builder/cb-expression.ts +49 -0
- package/src/condition-builder/cb-predicate.scss +35 -0
- package/src/condition-builder/cb-predicate.ts +102 -0
- package/src/condition-builder/condition-builder.scss +13 -0
- package/src/condition-builder/condition-builder.ts +38 -0
- package/src/condition-builder/index.ts +5 -0
- package/src/dropdown-button/demo/index.html +110 -0
- package/src/dropdown-button/dropdown-button.scss +22 -0
- package/src/dropdown-button/dropdown-button.ts +206 -0
- package/src/dropdown-button/index.ts +1 -0
- package/src/flow-designer/DEMO.md +239 -0
- package/src/flow-designer/commands.ts +278 -0
- package/src/flow-designer/flow-designer-node.ts +172 -0
- package/src/flow-designer/flow-designer.scss +457 -0
- package/src/flow-designer/flow-designer.ts +611 -0
- package/src/flow-designer/index.ts +41 -0
- package/src/flow-designer/layout.ts +357 -0
- package/src/flow-designer/types.ts +166 -0
- package/src/flow-designer/validation.ts +284 -0
- package/src/flow-designer/workflow-utils.ts +282 -0
- package/src/html-editor/html-editor.scss +188 -0
- package/src/html-editor/html-editor.ts +491 -0
- package/src/html-editor/index.ts +3 -0
- package/src/index.ts +27 -1
- package/src/list/index.ts +2 -0
- package/src/list/list-item.scss +111 -0
- package/src/list/list-item.ts +175 -0
- package/src/list/list.scss +24 -0
- package/src/list/list.ts +51 -0
- package/src/menu/menu/menu.scss +2 -2
- package/src/menu/menu/menu.ts +91 -101
- package/src/menu/menu-item/menu-item.scss +4 -0
- package/src/menu/menu-item/menu-item.ts +82 -78
- package/src/modal/index.ts +1 -0
- package/src/modal/modal.scss +206 -0
- package/src/modal/modal.ts +195 -0
- package/src/navigation-rail/navigation-rail-item.scss +7 -38
- package/src/navigation-rail/navigation-rail-item.ts +1 -2
- package/src/navigation-rail/navigation-rail.scss +17 -21
- package/src/navigation-rail/navigation-rail.ts +6 -9
- package/src/notification-manager/index.ts +1 -0
- package/src/notification-manager/notification-manager.scss +113 -0
- package/src/notification-manager/notification-manager.ts +199 -0
- package/src/number-field/number-field.ts +2 -2
- package/src/peacock-loader.ts +83 -0
- package/src/popover/index.ts +2 -0
- package/src/popover/popover-content.scss +69 -0
- package/src/popover/popover-content.ts +51 -0
- package/src/popover/popover.scss +7 -0
- package/src/popover/popover.ts +170 -0
- package/src/split-button/index.ts +1 -0
- package/src/split-button/split-button-colors.scss +56 -0
- package/src/split-button/split-button-sizes.scss +28 -0
- package/src/split-button/split-button.scss +79 -0
- package/src/split-button/split-button.ts +236 -0
- package/src/svg/index.ts +1 -0
- package/src/svg/svg.scss +91 -0
- package/src/svg/svg.ts +160 -0
- package/src/table/table.ts +2 -2
- package/src/toolbar/toolbar.ts +3 -3
- package/src/tooltip/tooltip.scss +4 -3
- package/src/tooltip/tooltip.ts +46 -104
- package/dist/button-DouvOfEU.js.map +0 -1
- package/dist/button-group-CEdMwvJJ.js +0 -464
- package/dist/button-group-CEdMwvJJ.js.map +0 -1
- package/dist/is-dark-mode-DicqGkCJ.js.map +0 -1
- package/dist/navigation-rail-Lxetd5-Z.js.map +0 -1
- package/dist/src/menu/menu/MenuSurfaceController.d.ts +0 -18
- package/src/menu/menu/MenuSurfaceController.ts +0 -61
|
@@ -0,0 +1,1656 @@
|
|
|
1
|
+
import { a as i, _ as __decorate, i as i$1, b, I as IndividualComponent, A } from './IndividualComponent-DUINtMGK.js';
|
|
2
|
+
import { n } from './property-1psGvXOq.js';
|
|
3
|
+
import { r } from './state-DwbEjqVk.js';
|
|
4
|
+
import { e as e$2 } from './query-QBcUV-L_.js';
|
|
5
|
+
import './toolbar.js';
|
|
6
|
+
import './icon-button-CK1ZuE-2.js';
|
|
7
|
+
import { e } from './directive-ZPhl09Yt.js';
|
|
8
|
+
import { e as e$1 } from './unsafe-html-BsGUjx94.js';
|
|
9
|
+
import { c as css_248z$1 } from './flow-designer-node-BWrPuxAR.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @license
|
|
13
|
+
* Copyright 2017 Google LLC
|
|
14
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
15
|
+
*/class t extends e$1{}t.directiveName="unsafeSVG",t.resultType=2;const o=e(t);
|
|
16
|
+
|
|
17
|
+
// Basic sanitization: remove <script>, <foreignObject>, event handler attributes (on*), and iframes
|
|
18
|
+
function sanitizeSvg(rawSvg) {
|
|
19
|
+
try {
|
|
20
|
+
const parser = new DOMParser();
|
|
21
|
+
const doc = parser.parseFromString(rawSvg, 'image/svg+xml');
|
|
22
|
+
const scripts = Array.from(doc.querySelectorAll('script'));
|
|
23
|
+
scripts.forEach(n => n.remove());
|
|
24
|
+
const foreigns = Array.from(doc.querySelectorAll('foreignObject, iframe'));
|
|
25
|
+
foreigns.forEach(n => n.remove());
|
|
26
|
+
const all = Array.from(doc.querySelectorAll('*'));
|
|
27
|
+
all.forEach(el => {
|
|
28
|
+
const attrs = Array.from(el.attributes).filter(a => /^on/i.test(a.name));
|
|
29
|
+
attrs.forEach(a => el.removeAttribute(a.name));
|
|
30
|
+
});
|
|
31
|
+
const el = doc.documentElement;
|
|
32
|
+
if (!el)
|
|
33
|
+
return '';
|
|
34
|
+
const serializer = new XMLSerializer();
|
|
35
|
+
return serializer.serializeToString(el);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
return '';
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function createCacheFetch(name) {
|
|
43
|
+
let cache = null;
|
|
44
|
+
// This map tracks requests currently being processed
|
|
45
|
+
const inFlightRequests = new Map();
|
|
46
|
+
try {
|
|
47
|
+
cache = await window.caches.open(name);
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
console.warn('window.caches access not allowed');
|
|
51
|
+
}
|
|
52
|
+
return async (url) => {
|
|
53
|
+
if (inFlightRequests.has(url)) {
|
|
54
|
+
return inFlightRequests.get(url);
|
|
55
|
+
}
|
|
56
|
+
const fetchPromise = (async () => {
|
|
57
|
+
const request = new Request(url);
|
|
58
|
+
if (cache) {
|
|
59
|
+
const cachedResponse = await cache.match(request);
|
|
60
|
+
if (cachedResponse) {
|
|
61
|
+
return cachedResponse.text();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
const urlObj = new URL(request.url);
|
|
65
|
+
const isSameOrigin = urlObj.origin === window.location.origin;
|
|
66
|
+
const response = await fetch(request.url, {
|
|
67
|
+
method: 'GET',
|
|
68
|
+
mode: isSameOrigin ? 'no-cors' : 'cors',
|
|
69
|
+
credentials: isSameOrigin ? 'same-origin' : 'omit',
|
|
70
|
+
});
|
|
71
|
+
if (response.status === 404) {
|
|
72
|
+
console.error(`[Fetch Error] Resource not found (404): ${url}`);
|
|
73
|
+
return '';
|
|
74
|
+
}
|
|
75
|
+
const result = await response.text();
|
|
76
|
+
if (cache && response.status === 200) {
|
|
77
|
+
await cache.put(request, new Response(result, {
|
|
78
|
+
status: response.status,
|
|
79
|
+
statusText: response.statusText,
|
|
80
|
+
headers: response.headers,
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
return result;
|
|
84
|
+
})();
|
|
85
|
+
inFlightRequests.set(url, fetchPromise);
|
|
86
|
+
try {
|
|
87
|
+
return await fetchPromise;
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
inFlightRequests.delete(url);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const PROVIDERS = {
|
|
96
|
+
'material-symbols': (name) => `https://cdn.jsdelivr.net/npm/@material-symbols/svg-500@0.40.1/outlined/${name}.svg`,
|
|
97
|
+
carbon: (name) => `https://cdn.jsdelivr.net/npm/@carbon/icons@11.41.0/svg/32/${name}.svg`,
|
|
98
|
+
};
|
|
99
|
+
const cacheFetch = await createCacheFetch('svg-cache');
|
|
100
|
+
async function fetchSVG(url) {
|
|
101
|
+
if (!url)
|
|
102
|
+
return '';
|
|
103
|
+
return cacheFetch(url);
|
|
104
|
+
}
|
|
105
|
+
async function fetchIcon(name, provider = 'material-symbols') {
|
|
106
|
+
if (!name)
|
|
107
|
+
return '';
|
|
108
|
+
if (!PROVIDERS[provider]) {
|
|
109
|
+
throw new Error(`Provider '${provider}' not found`);
|
|
110
|
+
}
|
|
111
|
+
return fetchSVG(PROVIDERS[provider](name));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
var css_248z = i`* {
|
|
115
|
+
box-sizing: border-box;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
.screen-reader-only {
|
|
119
|
+
display: none !important;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
:host {
|
|
123
|
+
display: inline-flex;
|
|
124
|
+
vertical-align: middle;
|
|
125
|
+
--icon-size: inherit;
|
|
126
|
+
--icon-color: inherit;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
.icon {
|
|
130
|
+
height: var(--icon-size, 1rem);
|
|
131
|
+
width: var(--icon-size, 1rem);
|
|
132
|
+
display: inline-flex;
|
|
133
|
+
align-items: center;
|
|
134
|
+
justify-content: center;
|
|
135
|
+
}
|
|
136
|
+
.icon svg {
|
|
137
|
+
fill: var(--icon-color);
|
|
138
|
+
height: 100%;
|
|
139
|
+
width: 100%;
|
|
140
|
+
}`;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @label Icon
|
|
144
|
+
* @tag wc-icon
|
|
145
|
+
* @rawTag icon
|
|
146
|
+
* @summary Icons are visual symbols used to represent ideas, objects, or actions.
|
|
147
|
+
* @overview Icons are visual symbols used to represent ideas, objects, or actions. They communicate messages at a glance, afford interactivity, and draw attention to important information.
|
|
148
|
+
*
|
|
149
|
+
* @cssprop --icon-color - Controls the color of the icon.
|
|
150
|
+
* @cssprop [--icon-size=1rem] - Controls the size of the icon. Defaults to "1rem"
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* ```html
|
|
154
|
+
* <wc-icon name="home" style="--icon-size: 2rem;"></wc-icon>
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
*/
|
|
158
|
+
class Icon extends i$1 {
|
|
159
|
+
constructor() {
|
|
160
|
+
super(...arguments);
|
|
161
|
+
this.provider = 'material-symbols';
|
|
162
|
+
this.svgContent = '';
|
|
163
|
+
// loading + error states for consumers/tests
|
|
164
|
+
this.loading = false;
|
|
165
|
+
this.error = null;
|
|
166
|
+
// token to avoid race conditions when multiple fetches overlap
|
|
167
|
+
this._fetchId = 0;
|
|
168
|
+
}
|
|
169
|
+
firstUpdated() {
|
|
170
|
+
// perform initial fetch once component is connected and rendered
|
|
171
|
+
this.__scheduleUpdate();
|
|
172
|
+
}
|
|
173
|
+
updated(changedProperties) {
|
|
174
|
+
// only refetch when name or src changed
|
|
175
|
+
if (changedProperties.has('name') || changedProperties.has('src')) {
|
|
176
|
+
this.__scheduleUpdate();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
render() {
|
|
180
|
+
// accessible wrapper; consumers can provide a fallback via <slot name="fallback">.
|
|
181
|
+
return b ` <div class="icon">
|
|
182
|
+
${this.svgContent
|
|
183
|
+
? o(this.svgContent)
|
|
184
|
+
: b `<slot name="fallback"></slot>`}
|
|
185
|
+
</div>`;
|
|
186
|
+
}
|
|
187
|
+
// small debounce to coalesce rapid changes (50ms)
|
|
188
|
+
__scheduleUpdate() {
|
|
189
|
+
if (this._debounceTimer) {
|
|
190
|
+
clearTimeout(this._debounceTimer);
|
|
191
|
+
}
|
|
192
|
+
// @ts-ignore - setTimeout in DOM returns number
|
|
193
|
+
this._debounceTimer = window.setTimeout(() => this.__updateSvg(), 50);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* @internal
|
|
197
|
+
*/
|
|
198
|
+
async __updateSvg() {
|
|
199
|
+
this._fetchId += 1;
|
|
200
|
+
const currentId = this._fetchId;
|
|
201
|
+
this.loading = true;
|
|
202
|
+
this.error = null;
|
|
203
|
+
try {
|
|
204
|
+
let raw;
|
|
205
|
+
if (this.name) {
|
|
206
|
+
raw = await fetchIcon(this.name, this.provider);
|
|
207
|
+
}
|
|
208
|
+
else if (this.src) {
|
|
209
|
+
raw = await fetchSVG(this.src);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
raw = '';
|
|
213
|
+
}
|
|
214
|
+
// If another fetch started after this one, ignore this result
|
|
215
|
+
if (currentId !== this._fetchId)
|
|
216
|
+
return;
|
|
217
|
+
if (raw) {
|
|
218
|
+
this.svgContent = sanitizeSvg(raw);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
this.svgContent = '';
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
catch (err) {
|
|
225
|
+
// capture and surface error, but avoid throwing
|
|
226
|
+
this.error = err instanceof Error ? err : new Error(String(err));
|
|
227
|
+
this.svgContent = '';
|
|
228
|
+
// bubble an event so consumers can react
|
|
229
|
+
this.dispatchEvent(new CustomEvent('icon-error', {
|
|
230
|
+
detail: { name: this.name, src: this.src, error: this.error },
|
|
231
|
+
bubbles: true,
|
|
232
|
+
composed: true,
|
|
233
|
+
}));
|
|
234
|
+
}
|
|
235
|
+
finally {
|
|
236
|
+
// ensure loading is cleared unless another fetch started
|
|
237
|
+
if (currentId === this._fetchId) {
|
|
238
|
+
this.loading = false;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
Icon.styles = [css_248z];
|
|
244
|
+
__decorate([
|
|
245
|
+
n({ type: String, reflect: true })
|
|
246
|
+
], Icon.prototype, "name", void 0);
|
|
247
|
+
__decorate([
|
|
248
|
+
n({ type: String, reflect: true })
|
|
249
|
+
], Icon.prototype, "src", void 0);
|
|
250
|
+
__decorate([
|
|
251
|
+
n({ type: String })
|
|
252
|
+
], Icon.prototype, "provider", void 0);
|
|
253
|
+
__decorate([
|
|
254
|
+
r()
|
|
255
|
+
], Icon.prototype, "svgContent", void 0);
|
|
256
|
+
__decorate([
|
|
257
|
+
r() // @ts-ignore
|
|
258
|
+
], Icon.prototype, "loading", void 0);
|
|
259
|
+
__decorate([
|
|
260
|
+
r()
|
|
261
|
+
], Icon.prototype, "error", void 0);
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Workflow utility functions for tree traversal and manipulation
|
|
265
|
+
*/
|
|
266
|
+
/**
|
|
267
|
+
* Deep clone a workflow to ensure immutability
|
|
268
|
+
*/
|
|
269
|
+
function cloneWorkflow(workflow) {
|
|
270
|
+
return JSON.parse(JSON.stringify(workflow));
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Deep clone a workflow node
|
|
274
|
+
*/
|
|
275
|
+
function cloneNode(node) {
|
|
276
|
+
return JSON.parse(JSON.stringify(node));
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Find a node by ID anywhere in the workflow tree
|
|
280
|
+
*/
|
|
281
|
+
function findNodeById(node, id) {
|
|
282
|
+
if (node.id === id)
|
|
283
|
+
return node;
|
|
284
|
+
// Search children
|
|
285
|
+
if (node.children) {
|
|
286
|
+
for (const child of node.children) {
|
|
287
|
+
const found = findNodeById(child, id);
|
|
288
|
+
if (found)
|
|
289
|
+
return found;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
// Search tasks
|
|
293
|
+
if (node.tasks) {
|
|
294
|
+
for (const task of node.tasks) {
|
|
295
|
+
const found = findNodeById(task, id);
|
|
296
|
+
if (found)
|
|
297
|
+
return found;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// Search branches
|
|
301
|
+
if (node.branches) {
|
|
302
|
+
for (const branchNodes of Object.values(node.branches)) {
|
|
303
|
+
for (const branchNode of branchNodes) {
|
|
304
|
+
const found = findNodeById(branchNode, id);
|
|
305
|
+
if (found)
|
|
306
|
+
return found;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
// Search join
|
|
311
|
+
if (node.join) {
|
|
312
|
+
const found = findNodeById(node.join, id);
|
|
313
|
+
if (found)
|
|
314
|
+
return found;
|
|
315
|
+
}
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Remove a node by ID from the workflow tree
|
|
320
|
+
*/
|
|
321
|
+
function removeNodeById(node, id) {
|
|
322
|
+
const result = cloneNode(node);
|
|
323
|
+
// Remove from children
|
|
324
|
+
if (result.children) {
|
|
325
|
+
result.children = result.children.filter((child) => {
|
|
326
|
+
if (child.id === id)
|
|
327
|
+
return false;
|
|
328
|
+
removeNodeById(child, id);
|
|
329
|
+
return true;
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
// Remove from tasks
|
|
333
|
+
if (result.tasks) {
|
|
334
|
+
result.tasks = result.tasks.filter((task) => {
|
|
335
|
+
if (task.id === id)
|
|
336
|
+
return false;
|
|
337
|
+
removeNodeById(task, id);
|
|
338
|
+
return true;
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
// Remove from branches
|
|
342
|
+
if (result.branches) {
|
|
343
|
+
for (const [branchKey, branchNodes] of Object.entries(result.branches)) {
|
|
344
|
+
result.branches[branchKey] = branchNodes.filter((branchNode) => {
|
|
345
|
+
if (branchNode.id === id)
|
|
346
|
+
return false;
|
|
347
|
+
removeNodeById(branchNode, id);
|
|
348
|
+
return true;
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
// Recursively clean empty nodes
|
|
353
|
+
for (const branchNode of result.children || []) {
|
|
354
|
+
removeNodeById(branchNode, id);
|
|
355
|
+
}
|
|
356
|
+
for (const taskNode of result.tasks || []) {
|
|
357
|
+
removeNodeById(taskNode, id);
|
|
358
|
+
}
|
|
359
|
+
for (const branchNodes of Object.values(result.branches || {})) {
|
|
360
|
+
for (const branchNode of branchNodes) {
|
|
361
|
+
removeNodeById(branchNode, id);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
return result;
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Insert a node into the workflow tree at a specific location
|
|
368
|
+
*/
|
|
369
|
+
function insertNodeIntoWorkflow(parent, nodeToInsert, connectionType = 'child', branchKey) {
|
|
370
|
+
switch (connectionType) {
|
|
371
|
+
case 'child':
|
|
372
|
+
if (!parent.children)
|
|
373
|
+
parent.children = [];
|
|
374
|
+
parent.children.push(cloneNode(nodeToInsert));
|
|
375
|
+
break;
|
|
376
|
+
case 'task':
|
|
377
|
+
if (!parent.tasks)
|
|
378
|
+
parent.tasks = [];
|
|
379
|
+
parent.tasks.push(cloneNode(nodeToInsert));
|
|
380
|
+
break;
|
|
381
|
+
case 'branch':
|
|
382
|
+
if (!parent.branches)
|
|
383
|
+
parent.branches = {};
|
|
384
|
+
if (!branchKey)
|
|
385
|
+
branchKey = 'default';
|
|
386
|
+
if (!parent.branches[branchKey])
|
|
387
|
+
parent.branches[branchKey] = [];
|
|
388
|
+
parent.branches[branchKey].push(cloneNode(nodeToInsert));
|
|
389
|
+
break;
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Collect all nodes in the workflow (depth-first)
|
|
394
|
+
*/
|
|
395
|
+
function getAllNodes(node) {
|
|
396
|
+
const result = [node];
|
|
397
|
+
if (node.children) {
|
|
398
|
+
for (const child of node.children) {
|
|
399
|
+
result.push(...getAllNodes(child));
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (node.tasks) {
|
|
403
|
+
for (const task of node.tasks) {
|
|
404
|
+
result.push(...getAllNodes(task));
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (node.branches) {
|
|
408
|
+
for (const branchNodes of Object.values(node.branches)) {
|
|
409
|
+
for (const branchNode of branchNodes) {
|
|
410
|
+
result.push(...getAllNodes(branchNode));
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
if (node.join) {
|
|
415
|
+
result.push(...getAllNodes(node.join));
|
|
416
|
+
}
|
|
417
|
+
return result;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* Get all parent node IDs for a given node (path from root to node)
|
|
421
|
+
*/
|
|
422
|
+
function getNodePath(rootNode, targetId) {
|
|
423
|
+
const path = [];
|
|
424
|
+
function traverse(node) {
|
|
425
|
+
path.push(node.id);
|
|
426
|
+
if (node.id === targetId)
|
|
427
|
+
return true;
|
|
428
|
+
// Search children
|
|
429
|
+
if (node.children) {
|
|
430
|
+
for (const child of node.children) {
|
|
431
|
+
if (traverse(child))
|
|
432
|
+
return true;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
// Search tasks
|
|
436
|
+
if (node.tasks) {
|
|
437
|
+
for (const task of node.tasks) {
|
|
438
|
+
if (traverse(task))
|
|
439
|
+
return true;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
// Search branches
|
|
443
|
+
if (node.branches) {
|
|
444
|
+
for (const branchNodes of Object.values(node.branches)) {
|
|
445
|
+
for (const branchNode of branchNodes) {
|
|
446
|
+
if (traverse(branchNode))
|
|
447
|
+
return true;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
// Search join
|
|
452
|
+
if (node.join) {
|
|
453
|
+
if (traverse(node.join))
|
|
454
|
+
return true;
|
|
455
|
+
}
|
|
456
|
+
path.pop();
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
traverse(rootNode);
|
|
460
|
+
return path;
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Check if a node is a descendant of another node
|
|
464
|
+
*/
|
|
465
|
+
function isDescendant(rootNode, potentialParentId, nodeId) {
|
|
466
|
+
const path = getNodePath(rootNode, nodeId);
|
|
467
|
+
return path.includes(potentialParentId);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Add Node Command
|
|
472
|
+
*/
|
|
473
|
+
class AddNodeCommand {
|
|
474
|
+
constructor(nodeToAdd, parentNodeId, connectionType = 'child', branchKey) {
|
|
475
|
+
this.nodeToAdd = nodeToAdd;
|
|
476
|
+
this.parentNodeId = parentNodeId;
|
|
477
|
+
this.connectionType = connectionType;
|
|
478
|
+
this.branchKey = branchKey;
|
|
479
|
+
this.description = 'Add node';
|
|
480
|
+
}
|
|
481
|
+
execute(workflow) {
|
|
482
|
+
const result = cloneWorkflow(workflow);
|
|
483
|
+
const parent = findNodeById(result.nodes, this.parentNodeId);
|
|
484
|
+
if (!parent)
|
|
485
|
+
return workflow; // Validation in parent component
|
|
486
|
+
insertNodeIntoWorkflow(parent, this.nodeToAdd, this.connectionType, this.branchKey);
|
|
487
|
+
return result;
|
|
488
|
+
}
|
|
489
|
+
undo(workflow) {
|
|
490
|
+
const result = cloneWorkflow(workflow);
|
|
491
|
+
removeNodeById(result.nodes, this.nodeToAdd.id);
|
|
492
|
+
return result;
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Delete Node Command
|
|
497
|
+
*/
|
|
498
|
+
class DeleteNodeCommand {
|
|
499
|
+
constructor(nodeId, workflow) {
|
|
500
|
+
this.nodeId = nodeId;
|
|
501
|
+
this.description = 'Delete node';
|
|
502
|
+
this.deletedNode = null;
|
|
503
|
+
this.parentReference = null;
|
|
504
|
+
if (workflow) {
|
|
505
|
+
this.captureNodeContext(workflow);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
captureNodeContext(workflow) {
|
|
509
|
+
const node = findNodeById(workflow.nodes, this.nodeId);
|
|
510
|
+
if (!node)
|
|
511
|
+
return;
|
|
512
|
+
this.deletedNode = cloneWorkflow({ workflow_id: '', nodes: node }).nodes;
|
|
513
|
+
// Find parent reference
|
|
514
|
+
this.findParentReference(workflow.nodes);
|
|
515
|
+
}
|
|
516
|
+
findParentReference(node) {
|
|
517
|
+
if (node.children) {
|
|
518
|
+
const idx = node.children.findIndex((n) => n.id === this.nodeId);
|
|
519
|
+
if (idx !== -1) {
|
|
520
|
+
this.parentReference = {
|
|
521
|
+
parentId: node.id,
|
|
522
|
+
connectionType: 'child',
|
|
523
|
+
};
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
for (const child of node.children) {
|
|
527
|
+
this.findParentReference(child);
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
if (node.tasks) {
|
|
531
|
+
const idx = node.tasks.findIndex((n) => n.id === this.nodeId);
|
|
532
|
+
if (idx !== -1) {
|
|
533
|
+
this.parentReference = {
|
|
534
|
+
parentId: node.id,
|
|
535
|
+
connectionType: 'task',
|
|
536
|
+
};
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
for (const task of node.tasks) {
|
|
540
|
+
this.findParentReference(task);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
if (node.branches) {
|
|
544
|
+
for (const [branchKey, branchNodes] of Object.entries(node.branches)) {
|
|
545
|
+
const idx = branchNodes.findIndex((n) => n.id === this.nodeId);
|
|
546
|
+
if (idx !== -1) {
|
|
547
|
+
this.parentReference = {
|
|
548
|
+
parentId: node.id,
|
|
549
|
+
connectionType: 'branch',
|
|
550
|
+
branchKey,
|
|
551
|
+
};
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
for (const branchNode of branchNodes) {
|
|
555
|
+
this.findParentReference(branchNode);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
execute(workflow) {
|
|
561
|
+
const result = cloneWorkflow(workflow);
|
|
562
|
+
removeNodeById(result.nodes, this.nodeId);
|
|
563
|
+
return result;
|
|
564
|
+
}
|
|
565
|
+
undo(workflow) {
|
|
566
|
+
if (!this.deletedNode || !this.parentReference)
|
|
567
|
+
return workflow;
|
|
568
|
+
const result = cloneWorkflow(workflow);
|
|
569
|
+
const parent = findNodeById(result.nodes, this.parentReference.parentId);
|
|
570
|
+
if (!parent)
|
|
571
|
+
return workflow;
|
|
572
|
+
insertNodeIntoWorkflow(parent, this.deletedNode, this.parentReference.connectionType, this.parentReference.branchKey);
|
|
573
|
+
return result;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
/**
|
|
577
|
+
* Edit Node Command
|
|
578
|
+
*/
|
|
579
|
+
class EditNodeCommand {
|
|
580
|
+
constructor(nodeId, updates, workflow) {
|
|
581
|
+
this.nodeId = nodeId;
|
|
582
|
+
this.updates = updates;
|
|
583
|
+
this.description = 'Edit node';
|
|
584
|
+
this.previousState = {};
|
|
585
|
+
if (workflow) {
|
|
586
|
+
const node = findNodeById(workflow.nodes, nodeId);
|
|
587
|
+
if (node) {
|
|
588
|
+
// Store only edited fields
|
|
589
|
+
Object.keys(updates).forEach((key) => {
|
|
590
|
+
this.previousState[key] = node[key];
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
execute(workflow) {
|
|
596
|
+
const result = cloneWorkflow(workflow);
|
|
597
|
+
const node = findNodeById(result.nodes, this.nodeId);
|
|
598
|
+
if (!node)
|
|
599
|
+
return workflow;
|
|
600
|
+
Object.assign(node, this.updates);
|
|
601
|
+
return result;
|
|
602
|
+
}
|
|
603
|
+
undo(workflow) {
|
|
604
|
+
const result = cloneWorkflow(workflow);
|
|
605
|
+
const node = findNodeById(result.nodes, this.nodeId);
|
|
606
|
+
if (!node)
|
|
607
|
+
return workflow;
|
|
608
|
+
Object.assign(node, this.previousState);
|
|
609
|
+
return result;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Move Node Command - reorder in array or change parent
|
|
614
|
+
*/
|
|
615
|
+
class MoveNodeCommand {
|
|
616
|
+
constructor(nodeId, newParentId, newIndex, newConnectionType = 'child', newBranchKey, workflow) {
|
|
617
|
+
this.nodeId = nodeId;
|
|
618
|
+
this.newParentId = newParentId;
|
|
619
|
+
this.newIndex = newIndex;
|
|
620
|
+
this.newConnectionType = newConnectionType;
|
|
621
|
+
this.newBranchKey = newBranchKey;
|
|
622
|
+
this.description = 'Move node';
|
|
623
|
+
this.previousState = null;
|
|
624
|
+
if (workflow) {
|
|
625
|
+
this.captureCurrentPosition(workflow);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
captureCurrentPosition(workflow) {
|
|
629
|
+
// Store current parent/position for undo
|
|
630
|
+
// Implementation depends on finding current parent location
|
|
631
|
+
}
|
|
632
|
+
execute(workflow) {
|
|
633
|
+
// Remove from old parent, insert at new parent
|
|
634
|
+
let result = cloneWorkflow(workflow);
|
|
635
|
+
result.nodes = removeNodeById(result.nodes, this.nodeId);
|
|
636
|
+
const newParent = findNodeById(result.nodes, this.newParentId);
|
|
637
|
+
if (!newParent)
|
|
638
|
+
return workflow;
|
|
639
|
+
const node = findNodeById(workflow.nodes, this.nodeId);
|
|
640
|
+
if (!node)
|
|
641
|
+
return workflow;
|
|
642
|
+
insertNodeIntoWorkflow(newParent, node, this.newConnectionType, this.newBranchKey);
|
|
643
|
+
return result;
|
|
644
|
+
}
|
|
645
|
+
undo(workflow) {
|
|
646
|
+
// Restore to previous position
|
|
647
|
+
if (!this.previousState)
|
|
648
|
+
return workflow;
|
|
649
|
+
let result = cloneWorkflow(workflow);
|
|
650
|
+
result.nodes = removeNodeById(result.nodes, this.nodeId);
|
|
651
|
+
const prevParent = findNodeById(result.nodes, this.previousState.parentId);
|
|
652
|
+
if (!prevParent)
|
|
653
|
+
return workflow;
|
|
654
|
+
const node = findNodeById(workflow.nodes, this.nodeId);
|
|
655
|
+
if (!node)
|
|
656
|
+
return workflow;
|
|
657
|
+
insertNodeIntoWorkflow(prevParent, node, this.previousState.connectionType, this.previousState.branchKey);
|
|
658
|
+
return result;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
const NODE_WIDTH = 200;
|
|
663
|
+
const NODE_HEIGHT = 100;
|
|
664
|
+
const HORIZONTAL_GAP = 60; // Gap between depth levels (columns)
|
|
665
|
+
const VERTICAL_GAP = 40; // Gap between lanes
|
|
666
|
+
const LANE_HEIGHT = 140; // Height of each swimlane row
|
|
667
|
+
const LANE_HEADER_HEIGHT = 84; // Top offset so first row is not clipped by floating UI
|
|
668
|
+
class SwimlaneLayout {
|
|
669
|
+
/**
|
|
670
|
+
* Calculate layout positions for all nodes in a workflow
|
|
671
|
+
*/
|
|
672
|
+
static calculateLayout(rootNode) {
|
|
673
|
+
const layoutNodes = [];
|
|
674
|
+
const lanes = new Map(); // lane -> nodes in that lane
|
|
675
|
+
// First pass: assign lanes and depths
|
|
676
|
+
this._traverseAndAssignLanes(rootNode, null, 'main', 0, layoutNodes, lanes);
|
|
677
|
+
// Second pass: calculate positions
|
|
678
|
+
const positionedNodes = [];
|
|
679
|
+
const nodePositions = new Map();
|
|
680
|
+
for (const layoutNode of layoutNodes) {
|
|
681
|
+
const x = layoutNode.depth * (NODE_WIDTH + HORIZONTAL_GAP) + HORIZONTAL_GAP;
|
|
682
|
+
const laneIndex = Array.from(lanes.keys()).indexOf(layoutNode.lane);
|
|
683
|
+
const y = laneIndex * (LANE_HEIGHT + VERTICAL_GAP) + LANE_HEADER_HEIGHT;
|
|
684
|
+
nodePositions.set(layoutNode.node.id, { x, y });
|
|
685
|
+
const positioned = {
|
|
686
|
+
node: layoutNode.node,
|
|
687
|
+
x,
|
|
688
|
+
y,
|
|
689
|
+
width: NODE_WIDTH,
|
|
690
|
+
height: NODE_HEIGHT,
|
|
691
|
+
lane: layoutNode.lane,
|
|
692
|
+
depth: layoutNode.depth,
|
|
693
|
+
branchPath: layoutNode.branchPath,
|
|
694
|
+
parentId: layoutNode.parent?.id,
|
|
695
|
+
connectorPoints: [],
|
|
696
|
+
};
|
|
697
|
+
positionedNodes.push(positioned);
|
|
698
|
+
}
|
|
699
|
+
// Third pass: calculate connector points
|
|
700
|
+
this._calculateConnectors(positionedNodes, nodePositions);
|
|
701
|
+
return positionedNodes;
|
|
702
|
+
}
|
|
703
|
+
/**
|
|
704
|
+
* Traverse workflow tree and assign lane/depth to each node
|
|
705
|
+
*/
|
|
706
|
+
static _traverseAndAssignLanes(node, parent, baseLane, depth, layoutNodes, lanes) {
|
|
707
|
+
const layoutNode = {
|
|
708
|
+
node,
|
|
709
|
+
parent,
|
|
710
|
+
lane: baseLane,
|
|
711
|
+
depth,
|
|
712
|
+
width: NODE_WIDTH,
|
|
713
|
+
height: NODE_HEIGHT,
|
|
714
|
+
};
|
|
715
|
+
// Add to layout nodes
|
|
716
|
+
layoutNodes.push(layoutNode);
|
|
717
|
+
// Register in lanes map
|
|
718
|
+
if (!lanes.has(baseLane)) {
|
|
719
|
+
lanes.set(baseLane, []);
|
|
720
|
+
}
|
|
721
|
+
lanes.get(baseLane).push(layoutNode);
|
|
722
|
+
// Process children
|
|
723
|
+
if (node.children && node.children.length > 0) {
|
|
724
|
+
for (const child of node.children) {
|
|
725
|
+
this._traverseAndAssignLanes(child, node, baseLane, depth + 1, layoutNodes, lanes);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
// Process decision branches into separate swimlanes
|
|
729
|
+
if (node.branches) {
|
|
730
|
+
let branchIndex = 0;
|
|
731
|
+
for (const [branchKey, branchNodes] of Object.entries(node.branches)) {
|
|
732
|
+
const branchLane = `${baseLane}_${branchKey}_${branchIndex}`;
|
|
733
|
+
for (const branchNode of branchNodes) {
|
|
734
|
+
this._traverseAndAssignLanes(branchNode, node, branchLane, depth + 1, layoutNodes, lanes);
|
|
735
|
+
}
|
|
736
|
+
branchIndex++;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
// Process fork into parallel lanes
|
|
740
|
+
if (node.type === 'fork' && node.tasks) {
|
|
741
|
+
let taskIndex = 0;
|
|
742
|
+
for (const task of node.tasks) {
|
|
743
|
+
const parallelLane = `${baseLane}_parallel_${taskIndex}`;
|
|
744
|
+
this._traverseAndAssignLanes(task, node, parallelLane, depth + 1, layoutNodes, lanes);
|
|
745
|
+
taskIndex++;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
// Process fork join node
|
|
749
|
+
if (node.type === 'fork' && node.join) {
|
|
750
|
+
// Join node goes back to main lane at next depth
|
|
751
|
+
this._traverseAndAssignLanes(node.join, node, baseLane, depth + 2, layoutNodes, lanes);
|
|
752
|
+
}
|
|
753
|
+
// Process task nodes (used in forks)
|
|
754
|
+
if (node.tasks && node.type !== 'fork') {
|
|
755
|
+
for (const task of node.tasks) {
|
|
756
|
+
this._traverseAndAssignLanes(task, node, baseLane, depth + 1, layoutNodes, lanes);
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Calculate SVG connector points between nodes
|
|
762
|
+
*/
|
|
763
|
+
static _calculateConnectors(positionedNodes, nodePositions) {
|
|
764
|
+
const nodeMap = new Map(positionedNodes.map((n) => [n.node.id, n]));
|
|
765
|
+
for (const positioned of positionedNodes) {
|
|
766
|
+
const connectors = [];
|
|
767
|
+
const nodeMiddleRight = {
|
|
768
|
+
x: positioned.x + positioned.width,
|
|
769
|
+
y: positioned.y + positioned.height / 2,
|
|
770
|
+
};
|
|
771
|
+
// Connect to children (sequential)
|
|
772
|
+
if (positioned.node.children && positioned.node.children.length > 0) {
|
|
773
|
+
for (const child of positioned.node.children) {
|
|
774
|
+
const childPos = nodeMap.get(child.id);
|
|
775
|
+
if (childPos) {
|
|
776
|
+
connectors.push({
|
|
777
|
+
from: nodeMiddleRight,
|
|
778
|
+
to: {
|
|
779
|
+
x: childPos.x,
|
|
780
|
+
y: childPos.y + childPos.height / 2,
|
|
781
|
+
},
|
|
782
|
+
type: 'straight',
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
// Connect to branches (decision)
|
|
788
|
+
if (positioned.node.branches) {
|
|
789
|
+
for (const branchNodes of Object.values(positioned.node.branches)) {
|
|
790
|
+
for (const branchNode of branchNodes) {
|
|
791
|
+
const childPos = nodeMap.get(branchNode.id);
|
|
792
|
+
if (childPos) {
|
|
793
|
+
// Curved path to branch
|
|
794
|
+
connectors.push({
|
|
795
|
+
from: nodeMiddleRight,
|
|
796
|
+
to: {
|
|
797
|
+
x: childPos.x,
|
|
798
|
+
y: childPos.y + childPos.height / 2,
|
|
799
|
+
},
|
|
800
|
+
type: 'branch',
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
// Connect fork to parallel tasks
|
|
807
|
+
if (positioned.node.type === 'fork' && positioned.node.tasks) {
|
|
808
|
+
for (const task of positioned.node.tasks) {
|
|
809
|
+
const taskPos = nodeMap.get(task.id);
|
|
810
|
+
if (taskPos) {
|
|
811
|
+
connectors.push({
|
|
812
|
+
from: nodeMiddleRight,
|
|
813
|
+
to: {
|
|
814
|
+
x: taskPos.x,
|
|
815
|
+
y: taskPos.y + taskPos.height / 2,
|
|
816
|
+
},
|
|
817
|
+
type: 'fork',
|
|
818
|
+
});
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
// Connect to join
|
|
823
|
+
if (positioned.node.type === 'fork' && positioned.node.join) {
|
|
824
|
+
const joinPos = nodeMap.get(positioned.node.join.id);
|
|
825
|
+
if (joinPos) {
|
|
826
|
+
connectors.push({
|
|
827
|
+
from: nodeMiddleRight,
|
|
828
|
+
to: {
|
|
829
|
+
x: joinPos.x,
|
|
830
|
+
y: joinPos.y + joinPos.height / 2,
|
|
831
|
+
},
|
|
832
|
+
type: 'join',
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
// Connect loop back
|
|
837
|
+
if (positioned.node.type === 'loop_end' && positioned.node.target_id) {
|
|
838
|
+
const targetPos = nodeMap.get(positioned.node.target_id);
|
|
839
|
+
if (targetPos) {
|
|
840
|
+
connectors.push({
|
|
841
|
+
from: {
|
|
842
|
+
x: positioned.x + positioned.width,
|
|
843
|
+
y: positioned.y + positioned.height / 2,
|
|
844
|
+
},
|
|
845
|
+
to: {
|
|
846
|
+
x: targetPos.x,
|
|
847
|
+
y: targetPos.y + targetPos.height / 2,
|
|
848
|
+
},
|
|
849
|
+
type: 'curved',
|
|
850
|
+
});
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
positioned.connectorPoints = connectors;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Get swimlane configurations for rendering
|
|
858
|
+
*/
|
|
859
|
+
static getSwimlanes(positionedNodes) {
|
|
860
|
+
const swimlanesMap = new Map();
|
|
861
|
+
for (const node of positionedNodes) {
|
|
862
|
+
if (!swimlanesMap.has(node.lane)) {
|
|
863
|
+
swimlanesMap.set(node.lane, []);
|
|
864
|
+
}
|
|
865
|
+
swimlanesMap.get(node.lane).push(node);
|
|
866
|
+
}
|
|
867
|
+
const swimlanes = [];
|
|
868
|
+
for (const [laneId, nodes] of swimlanesMap.entries()) {
|
|
869
|
+
const isParallel = laneId.includes('parallel');
|
|
870
|
+
const name = this._getSwimlaneName(laneId);
|
|
871
|
+
swimlanes.push({
|
|
872
|
+
id: laneId,
|
|
873
|
+
name,
|
|
874
|
+
nodes,
|
|
875
|
+
isParallel,
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
return swimlanes;
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Generate human-readable swimlane name
|
|
882
|
+
*/
|
|
883
|
+
static _getSwimlaneName(laneId) {
|
|
884
|
+
if (laneId === 'main')
|
|
885
|
+
return 'Main Flow';
|
|
886
|
+
if (laneId.includes('yes'))
|
|
887
|
+
return 'Yes Path';
|
|
888
|
+
if (laneId.includes('no'))
|
|
889
|
+
return 'No Path';
|
|
890
|
+
if (laneId.includes('parallel')) {
|
|
891
|
+
const match = laneId.match(/parallel_(\d+)/);
|
|
892
|
+
if (match)
|
|
893
|
+
return `Parallel Task ${parseInt(match[1]) + 1}`;
|
|
894
|
+
}
|
|
895
|
+
return laneId;
|
|
896
|
+
}
|
|
897
|
+
/**
|
|
898
|
+
* Calculate canvas bounds for sizing
|
|
899
|
+
*/
|
|
900
|
+
static getCanvasBounds(positionedNodes) {
|
|
901
|
+
if (positionedNodes.length === 0) {
|
|
902
|
+
return { width: 600, height: 400 };
|
|
903
|
+
}
|
|
904
|
+
let maxX = 0;
|
|
905
|
+
let maxY = 0;
|
|
906
|
+
for (const node of positionedNodes) {
|
|
907
|
+
maxX = Math.max(maxX, node.x + node.width + HORIZONTAL_GAP);
|
|
908
|
+
maxY = Math.max(maxY, node.y + node.height + VERTICAL_GAP);
|
|
909
|
+
}
|
|
910
|
+
return {
|
|
911
|
+
width: Math.max(600, maxX),
|
|
912
|
+
height: Math.max(400, maxY),
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
|
|
917
|
+
/**
|
|
918
|
+
* Workflow validation - checks for common errors and inconsistencies
|
|
919
|
+
*/
|
|
920
|
+
class WorkflowValidator {
|
|
921
|
+
/**
|
|
922
|
+
* Validate entire workflow
|
|
923
|
+
*/
|
|
924
|
+
static validate(workflow) {
|
|
925
|
+
const errors = [];
|
|
926
|
+
// Check root node exists and is a trigger
|
|
927
|
+
if (!workflow.nodes) {
|
|
928
|
+
errors.push({
|
|
929
|
+
nodeId: 'root',
|
|
930
|
+
type: 'orphaned_node',
|
|
931
|
+
message: 'Workflow has no root node',
|
|
932
|
+
severity: 'error',
|
|
933
|
+
});
|
|
934
|
+
return errors;
|
|
935
|
+
}
|
|
936
|
+
// Validate all nodes
|
|
937
|
+
const allNodes = getAllNodes(workflow.nodes);
|
|
938
|
+
// Check for circular loops
|
|
939
|
+
errors.push(...this._checkCircularLoops(workflow.nodes, allNodes));
|
|
940
|
+
// Check for orphaned nodes
|
|
941
|
+
errors.push(...this._checkOrphanedNodes(workflow.nodes, allNodes));
|
|
942
|
+
// Check valid branches
|
|
943
|
+
errors.push(...this._checkValidBranches(workflow.nodes, allNodes));
|
|
944
|
+
// Check missing targets
|
|
945
|
+
errors.push(...this._checkMissingTargets(workflow, allNodes));
|
|
946
|
+
// Check invalid fork/join pairs
|
|
947
|
+
errors.push(...this._checkForkJoinPairs(workflow.nodes, allNodes));
|
|
948
|
+
return errors;
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Detect circular loop references
|
|
952
|
+
* A loop_end cannot point to a node that is its own descendant (after the loop_start)
|
|
953
|
+
*/
|
|
954
|
+
static _checkCircularLoops(rootNode, allNodes) {
|
|
955
|
+
const errors = [];
|
|
956
|
+
for (const node of allNodes) {
|
|
957
|
+
// Only check loop_end nodes
|
|
958
|
+
if (node.type !== 'loop_end')
|
|
959
|
+
continue;
|
|
960
|
+
const targetId = node.target_id;
|
|
961
|
+
if (!targetId)
|
|
962
|
+
continue;
|
|
963
|
+
// Check if target exists
|
|
964
|
+
const targetNode = findNodeById(rootNode, targetId);
|
|
965
|
+
if (!targetNode)
|
|
966
|
+
continue;
|
|
967
|
+
// If loop_end is a descendant of its target, it's circular
|
|
968
|
+
if (isDescendant(rootNode, targetId, node.id)) ;
|
|
969
|
+
// However, if the loop_end's target is a descendant of the loop_end, that's circular
|
|
970
|
+
if (isDescendant(rootNode, node.id, targetId)) {
|
|
971
|
+
errors.push({
|
|
972
|
+
nodeId: node.id,
|
|
973
|
+
type: 'circular_loop',
|
|
974
|
+
message: `Loop cannot point to a node (${targetId}) that executes after the loop_end`,
|
|
975
|
+
severity: 'error',
|
|
976
|
+
});
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
return errors;
|
|
980
|
+
}
|
|
981
|
+
/**
|
|
982
|
+
* Check for orphaned nodes (not reachable from root)
|
|
983
|
+
*/
|
|
984
|
+
static _checkOrphanedNodes(rootNode, allNodes) {
|
|
985
|
+
const errors = [];
|
|
986
|
+
const paths = new Map();
|
|
987
|
+
for (const node of allNodes) {
|
|
988
|
+
const path = getNodePath(rootNode, node.id);
|
|
989
|
+
if (path.length === 0 && node.id !== rootNode.id) {
|
|
990
|
+
errors.push({
|
|
991
|
+
nodeId: node.id,
|
|
992
|
+
type: 'orphaned_node',
|
|
993
|
+
message: `Node "${node.label}" is not reachable from the root trigger`,
|
|
994
|
+
severity: 'error',
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
paths.set(node.id, path);
|
|
998
|
+
}
|
|
999
|
+
// Check nodes in branches - all branch paths must be reachable
|
|
1000
|
+
// This is typically valid by structure, but warn if branch has no exit
|
|
1001
|
+
for (const node of allNodes) {
|
|
1002
|
+
if (!node.branches)
|
|
1003
|
+
continue;
|
|
1004
|
+
for (const [branchKey, branchNodes] of Object.entries(node.branches)) {
|
|
1005
|
+
if (branchNodes.length === 0) {
|
|
1006
|
+
errors.push({
|
|
1007
|
+
nodeId: node.id,
|
|
1008
|
+
type: 'invalid_branch',
|
|
1009
|
+
message: `Branch "${branchKey}" is empty - no nodes to execute`,
|
|
1010
|
+
severity: 'warning',
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
return errors;
|
|
1016
|
+
}
|
|
1017
|
+
/**
|
|
1018
|
+
* Check that decision nodes have valid branches
|
|
1019
|
+
*/
|
|
1020
|
+
static _checkValidBranches(rootNode, allNodes) {
|
|
1021
|
+
const errors = [];
|
|
1022
|
+
for (const node of allNodes) {
|
|
1023
|
+
if (node.type !== 'decision')
|
|
1024
|
+
continue;
|
|
1025
|
+
if (!node.branches) {
|
|
1026
|
+
errors.push({
|
|
1027
|
+
nodeId: node.id,
|
|
1028
|
+
type: 'invalid_branch',
|
|
1029
|
+
message: `Decision node "${node.label}" has no branches defined`,
|
|
1030
|
+
severity: 'error',
|
|
1031
|
+
});
|
|
1032
|
+
continue;
|
|
1033
|
+
}
|
|
1034
|
+
// Standard decision should have "yes" and "no"
|
|
1035
|
+
const branchKeys = Object.keys(node.branches);
|
|
1036
|
+
if (!branchKeys.includes('yes') || !branchKeys.includes('no')) {
|
|
1037
|
+
errors.push({
|
|
1038
|
+
nodeId: node.id,
|
|
1039
|
+
type: 'invalid_branch',
|
|
1040
|
+
message: `Decision node "${node.label}" should have "yes" and "no" branches`,
|
|
1041
|
+
severity: 'warning',
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
// Check for empty branches
|
|
1045
|
+
for (const [branchKey, branchNodes] of Object.entries(node.branches)) {
|
|
1046
|
+
if (branchNodes.length === 0) {
|
|
1047
|
+
errors.push({
|
|
1048
|
+
nodeId: node.id,
|
|
1049
|
+
type: 'invalid_branch',
|
|
1050
|
+
message: `Decision branch "${branchKey}" is empty`,
|
|
1051
|
+
severity: 'warning',
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1056
|
+
return errors;
|
|
1057
|
+
}
|
|
1058
|
+
/**
|
|
1059
|
+
* Check that loop_end nodes reference valid loop_start nodes
|
|
1060
|
+
*/
|
|
1061
|
+
static _checkMissingTargets(workflow, allNodes) {
|
|
1062
|
+
const errors = [];
|
|
1063
|
+
for (const node of allNodes) {
|
|
1064
|
+
if (node.type === 'loop_end') {
|
|
1065
|
+
if (!node.target_id) {
|
|
1066
|
+
errors.push({
|
|
1067
|
+
nodeId: node.id,
|
|
1068
|
+
type: 'missing_target',
|
|
1069
|
+
message: `Loop end "${node.label}" does not specify a target loop_start`,
|
|
1070
|
+
severity: 'error',
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
else {
|
|
1074
|
+
const target = findNodeById(workflow.nodes, node.target_id);
|
|
1075
|
+
if (!target || target.type !== 'loop_start') {
|
|
1076
|
+
errors.push({
|
|
1077
|
+
nodeId: node.id,
|
|
1078
|
+
type: 'missing_target',
|
|
1079
|
+
message: `Loop end "${node.label}" references non-existent or non-loop_start node "${node.target_id}"`,
|
|
1080
|
+
severity: 'error',
|
|
1081
|
+
});
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
return errors;
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* Check that fork nodes have corresponding join nodes
|
|
1090
|
+
*/
|
|
1091
|
+
static _checkForkJoinPairs(rootNode, allNodes) {
|
|
1092
|
+
const errors = [];
|
|
1093
|
+
for (const node of allNodes) {
|
|
1094
|
+
if (node.type === 'fork') {
|
|
1095
|
+
if (!node.join) {
|
|
1096
|
+
errors.push({
|
|
1097
|
+
nodeId: node.id,
|
|
1098
|
+
type: 'invalid_fork_join',
|
|
1099
|
+
message: `Fork node "${node.label}" does not have a corresponding join node`,
|
|
1100
|
+
severity: 'error',
|
|
1101
|
+
});
|
|
1102
|
+
}
|
|
1103
|
+
else if (node.join.type !== 'join') {
|
|
1104
|
+
errors.push({
|
|
1105
|
+
nodeId: node.id,
|
|
1106
|
+
type: 'invalid_fork_join',
|
|
1107
|
+
message: `Fork node "${node.label}" join is not a join node`,
|
|
1108
|
+
severity: 'error',
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
if (!node.tasks || node.tasks.length === 0) {
|
|
1112
|
+
errors.push({
|
|
1113
|
+
nodeId: node.id,
|
|
1114
|
+
type: 'invalid_fork_join',
|
|
1115
|
+
message: `Fork node "${node.label}" has no parallel tasks`,
|
|
1116
|
+
severity: 'warning',
|
|
1117
|
+
});
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
return errors;
|
|
1122
|
+
}
|
|
1123
|
+
/**
|
|
1124
|
+
* Check if workflow would create a valid execution path
|
|
1125
|
+
*/
|
|
1126
|
+
static isExecutable(workflow) {
|
|
1127
|
+
const errors = this.validate(workflow);
|
|
1128
|
+
return errors.filter((e) => e.severity === 'error').length === 0;
|
|
1129
|
+
}
|
|
1130
|
+
/**
|
|
1131
|
+
* Get validation warnings only
|
|
1132
|
+
*/
|
|
1133
|
+
static getWarnings(workflow) {
|
|
1134
|
+
const errors = this.validate(workflow);
|
|
1135
|
+
return errors.filter((e) => e.severity === 'warning');
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* Get validation errors only
|
|
1139
|
+
*/
|
|
1140
|
+
static getErrors(workflow) {
|
|
1141
|
+
const errors = this.validate(workflow);
|
|
1142
|
+
return errors.filter((e) => e.severity === 'error');
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
/**
|
|
1147
|
+
* @label Flow Designer
|
|
1148
|
+
* @tag wc-flow-designer
|
|
1149
|
+
* @rawTag flow-designer
|
|
1150
|
+
* @summary Low-code business process flow designer with swimlane layout, undo/redo, and interactive editing.
|
|
1151
|
+
*
|
|
1152
|
+
* @cssprop --flow-designer-height - Height of the flow designer container. Defaults to 400px.
|
|
1153
|
+
* @cssprop --flow-designer-border-color - Border color of the flow designer. Defaults to outline-variant.
|
|
1154
|
+
* @cssprop --flow-designer-background - Background color of the designer. Defaults to surface.
|
|
1155
|
+
* @cssprop --flow-designer-border-radius - Corner radius. Defaults to medium shape.
|
|
1156
|
+
* @cssprop --flow-designer-action-bar-bg - Background color of the action bar. Defaults to surface-container.
|
|
1157
|
+
*
|
|
1158
|
+
* @example
|
|
1159
|
+
* ```html
|
|
1160
|
+
* <wc-flow-designer id="editor"></wc-flow-designer>
|
|
1161
|
+
* <script>
|
|
1162
|
+
* const workflow = {
|
|
1163
|
+
* workflow_id: "demo",
|
|
1164
|
+
* nodes: {
|
|
1165
|
+
* id: "node_1",
|
|
1166
|
+
* type: "trigger",
|
|
1167
|
+
* label: "Start"
|
|
1168
|
+
* }
|
|
1169
|
+
* };
|
|
1170
|
+
* document.querySelector('#editor').workflow = workflow;
|
|
1171
|
+
* </script>
|
|
1172
|
+
* ```
|
|
1173
|
+
*/
|
|
1174
|
+
let FlowDesigner = class FlowDesigner extends i$1 {
|
|
1175
|
+
constructor() {
|
|
1176
|
+
super(...arguments);
|
|
1177
|
+
/**
|
|
1178
|
+
* The workflow definition to display and edit
|
|
1179
|
+
*/
|
|
1180
|
+
this.workflow = { workflow_id: '', nodes: { id: 'root', type: 'trigger', label: 'Start' } };
|
|
1181
|
+
/**
|
|
1182
|
+
* Whether the flow designer is in read-only mode
|
|
1183
|
+
*/
|
|
1184
|
+
this.readonly = false;
|
|
1185
|
+
/**
|
|
1186
|
+
* Whether the flow designer is disabled
|
|
1187
|
+
*/
|
|
1188
|
+
this.disabled = false;
|
|
1189
|
+
/**
|
|
1190
|
+
* Show validation errors/warnings
|
|
1191
|
+
*/
|
|
1192
|
+
this.showValidation = false;
|
|
1193
|
+
this._editor = {
|
|
1194
|
+
selectedNodeId: null,
|
|
1195
|
+
isEditing: false,
|
|
1196
|
+
editingNode: null,
|
|
1197
|
+
hoveredNodeId: null,
|
|
1198
|
+
isDragging: false,
|
|
1199
|
+
draggedNodeId: null,
|
|
1200
|
+
zoom: 1,
|
|
1201
|
+
panX: 0,
|
|
1202
|
+
panY: 0,
|
|
1203
|
+
};
|
|
1204
|
+
this._positionedNodes = [];
|
|
1205
|
+
this._history = [];
|
|
1206
|
+
this._historyIndex = -1;
|
|
1207
|
+
this._isDragScrolling = false;
|
|
1208
|
+
this._dragStartX = 0;
|
|
1209
|
+
this._dragStartY = 0;
|
|
1210
|
+
this._scrollStartX = 0;
|
|
1211
|
+
this._scrollStartY = 0;
|
|
1212
|
+
this._handleKeyDown = (event) => {
|
|
1213
|
+
if (this.disabled || this.readonly)
|
|
1214
|
+
return;
|
|
1215
|
+
if (event.ctrlKey || event.metaKey) {
|
|
1216
|
+
if (event.key === 'z') {
|
|
1217
|
+
event.preventDefault();
|
|
1218
|
+
this.undo();
|
|
1219
|
+
}
|
|
1220
|
+
else if (event.key === 'y') {
|
|
1221
|
+
event.preventDefault();
|
|
1222
|
+
this.redo();
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
if (event.key === 'Delete' && this._editor.selectedNodeId) {
|
|
1226
|
+
event.preventDefault();
|
|
1227
|
+
this.deleteNode(this._editor.selectedNodeId);
|
|
1228
|
+
}
|
|
1229
|
+
};
|
|
1230
|
+
this._handleMouseUp = () => {
|
|
1231
|
+
this._isDragScrolling = false;
|
|
1232
|
+
};
|
|
1233
|
+
this._handleCanvasMouseDown = (e) => {
|
|
1234
|
+
if (this.disabled)
|
|
1235
|
+
return;
|
|
1236
|
+
if (e.target === this.scrollElm || e.target.classList.contains('canvas-container')) {
|
|
1237
|
+
this._isDragScrolling = true;
|
|
1238
|
+
this._dragStartX = e.clientX;
|
|
1239
|
+
this._dragStartY = e.clientY;
|
|
1240
|
+
if (this.scrollElm) {
|
|
1241
|
+
this._scrollStartX = this.scrollElm.scrollLeft;
|
|
1242
|
+
this._scrollStartY = this.scrollElm.scrollTop;
|
|
1243
|
+
}
|
|
1244
|
+
}
|
|
1245
|
+
};
|
|
1246
|
+
this._handleCanvasMouseMove = (e) => {
|
|
1247
|
+
if (!this._isDragScrolling || !this.scrollElm)
|
|
1248
|
+
return;
|
|
1249
|
+
const deltaX = e.clientX - this._dragStartX;
|
|
1250
|
+
const deltaY = e.clientY - this._dragStartY;
|
|
1251
|
+
this.scrollElm.scrollLeft = this._scrollStartX - deltaX;
|
|
1252
|
+
this.scrollElm.scrollTop = this._scrollStartY - deltaY;
|
|
1253
|
+
};
|
|
1254
|
+
this._handleNodeClick = (e) => {
|
|
1255
|
+
const nodeId = e.detail.nodeId;
|
|
1256
|
+
this._editor.selectedNodeId = nodeId;
|
|
1257
|
+
this.requestUpdate();
|
|
1258
|
+
};
|
|
1259
|
+
this._handleNodeDelete = (e) => {
|
|
1260
|
+
const nodeId = e.detail.nodeId;
|
|
1261
|
+
this.deleteNode(nodeId);
|
|
1262
|
+
};
|
|
1263
|
+
this._handleNodeEdit = (e) => {
|
|
1264
|
+
const nodeId = e.detail.nodeId;
|
|
1265
|
+
this._editor.selectedNodeId = nodeId;
|
|
1266
|
+
this._editor.isEditing = true;
|
|
1267
|
+
this.requestUpdate();
|
|
1268
|
+
};
|
|
1269
|
+
this._handleZoomIn = () => {
|
|
1270
|
+
this._editor.zoom = Math.min(2, this._editor.zoom + 0.1);
|
|
1271
|
+
this.requestUpdate();
|
|
1272
|
+
};
|
|
1273
|
+
this._handleZoomOut = () => {
|
|
1274
|
+
this._editor.zoom = Math.max(0.5, this._editor.zoom - 0.1);
|
|
1275
|
+
this.requestUpdate();
|
|
1276
|
+
};
|
|
1277
|
+
}
|
|
1278
|
+
connectedCallback() {
|
|
1279
|
+
super.connectedCallback();
|
|
1280
|
+
window.addEventListener('mouseup', this._handleMouseUp);
|
|
1281
|
+
window.addEventListener('keydown', this._handleKeyDown);
|
|
1282
|
+
this._recalculateLayout();
|
|
1283
|
+
}
|
|
1284
|
+
disconnectedCallback() {
|
|
1285
|
+
window.removeEventListener('mouseup', this._handleMouseUp);
|
|
1286
|
+
window.removeEventListener('keydown', this._handleKeyDown);
|
|
1287
|
+
super.disconnectedCallback();
|
|
1288
|
+
}
|
|
1289
|
+
willUpdate() {
|
|
1290
|
+
this._recalculateLayout();
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* Recalculate layout when workflow changes
|
|
1294
|
+
*/
|
|
1295
|
+
_recalculateLayout() {
|
|
1296
|
+
if (!this.workflow?.nodes)
|
|
1297
|
+
return;
|
|
1298
|
+
this._positionedNodes = SwimlaneLayout.calculateLayout(this.workflow.nodes);
|
|
1299
|
+
}
|
|
1300
|
+
/**
|
|
1301
|
+
* Add a new node
|
|
1302
|
+
*/
|
|
1303
|
+
addNode(newNode, parentNodeId, connectionType = 'child', branchKey) {
|
|
1304
|
+
const command = new AddNodeCommand(newNode, parentNodeId, connectionType, branchKey);
|
|
1305
|
+
this._executeCommand(command);
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Delete a node by ID
|
|
1309
|
+
*/
|
|
1310
|
+
deleteNode(nodeId) {
|
|
1311
|
+
const command = new DeleteNodeCommand(nodeId, this.workflow);
|
|
1312
|
+
this._executeCommand(command);
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Edit a node
|
|
1316
|
+
*/
|
|
1317
|
+
editNode(nodeId, updates) {
|
|
1318
|
+
const command = new EditNodeCommand(nodeId, updates, this.workflow);
|
|
1319
|
+
this._executeCommand(command);
|
|
1320
|
+
}
|
|
1321
|
+
/**
|
|
1322
|
+
* Move a node to a different parent/position
|
|
1323
|
+
*/
|
|
1324
|
+
moveNode(nodeId, newParentId, newIndex, connectionType = 'child', branchKey) {
|
|
1325
|
+
const command = new MoveNodeCommand(nodeId, newParentId, newIndex, connectionType, branchKey, this.workflow);
|
|
1326
|
+
this._executeCommand(command);
|
|
1327
|
+
}
|
|
1328
|
+
/**
|
|
1329
|
+
* Execute a command and add to history
|
|
1330
|
+
*/
|
|
1331
|
+
_executeCommand(command) {
|
|
1332
|
+
const newWorkflow = command.execute(this.workflow);
|
|
1333
|
+
// Validate workflow after change
|
|
1334
|
+
const errors = WorkflowValidator.validate(newWorkflow);
|
|
1335
|
+
const hasErrors = errors.some((e) => e.severity === 'error');
|
|
1336
|
+
if (hasErrors && !confirm('Workflow has errors. Continue anyway?')) {
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
1339
|
+
// Add to history
|
|
1340
|
+
this._history = this._history.slice(0, this._historyIndex + 1);
|
|
1341
|
+
this._history.push({
|
|
1342
|
+
command,
|
|
1343
|
+
workflow: newWorkflow,
|
|
1344
|
+
timestamp: Date.now(),
|
|
1345
|
+
});
|
|
1346
|
+
this._historyIndex++;
|
|
1347
|
+
// Update workflow
|
|
1348
|
+
this.workflow = newWorkflow;
|
|
1349
|
+
// Emit change event
|
|
1350
|
+
this._emitWorkflowChange('node-edited', undefined);
|
|
1351
|
+
}
|
|
1352
|
+
/**
|
|
1353
|
+
* Undo last operation
|
|
1354
|
+
*/
|
|
1355
|
+
undo() {
|
|
1356
|
+
if (this._historyIndex <= 0)
|
|
1357
|
+
return;
|
|
1358
|
+
this._historyIndex--;
|
|
1359
|
+
const entry = this._history[this._historyIndex];
|
|
1360
|
+
this.workflow = cloneWorkflow(entry.workflow);
|
|
1361
|
+
this._emitWorkflowChange('undo', undefined);
|
|
1362
|
+
}
|
|
1363
|
+
/**
|
|
1364
|
+
* Redo last undone operation
|
|
1365
|
+
*/
|
|
1366
|
+
redo() {
|
|
1367
|
+
if (this._historyIndex >= this._history.length - 1)
|
|
1368
|
+
return;
|
|
1369
|
+
this._historyIndex++;
|
|
1370
|
+
const entry = this._history[this._historyIndex];
|
|
1371
|
+
this.workflow = cloneWorkflow(entry.workflow);
|
|
1372
|
+
this._emitWorkflowChange('redo', undefined);
|
|
1373
|
+
}
|
|
1374
|
+
/**
|
|
1375
|
+
* Check if undo is available
|
|
1376
|
+
*/
|
|
1377
|
+
canUndo() {
|
|
1378
|
+
return this._historyIndex > 0;
|
|
1379
|
+
}
|
|
1380
|
+
/**
|
|
1381
|
+
* Check if redo is available
|
|
1382
|
+
*/
|
|
1383
|
+
canRedo() {
|
|
1384
|
+
return this._historyIndex < this._history.length - 1;
|
|
1385
|
+
}
|
|
1386
|
+
/**
|
|
1387
|
+
* Export current workflow as JSON
|
|
1388
|
+
*/
|
|
1389
|
+
exportWorkflow() {
|
|
1390
|
+
return JSON.stringify(this.workflow, null, 2);
|
|
1391
|
+
}
|
|
1392
|
+
/**
|
|
1393
|
+
* Validate workflow
|
|
1394
|
+
*/
|
|
1395
|
+
validate() {
|
|
1396
|
+
const errors = WorkflowValidator.validate(this.workflow);
|
|
1397
|
+
this.dispatchEvent(new CustomEvent('validation-result', {
|
|
1398
|
+
detail: { errors },
|
|
1399
|
+
bubbles: true,
|
|
1400
|
+
composed: true,
|
|
1401
|
+
}));
|
|
1402
|
+
}
|
|
1403
|
+
_emitWorkflowChange(type, nodeId) {
|
|
1404
|
+
this.dispatchEvent(new CustomEvent('workflow-changed', {
|
|
1405
|
+
detail: {
|
|
1406
|
+
type,
|
|
1407
|
+
nodeId,
|
|
1408
|
+
workflow: this.workflow,
|
|
1409
|
+
},
|
|
1410
|
+
bubbles: true,
|
|
1411
|
+
composed: true,
|
|
1412
|
+
}));
|
|
1413
|
+
}
|
|
1414
|
+
render() {
|
|
1415
|
+
if (!this.workflow?.nodes) {
|
|
1416
|
+
return b `<div class="flow-designer-container">
|
|
1417
|
+
<p class="empty-state">No workflow loaded</p>
|
|
1418
|
+
</div>`;
|
|
1419
|
+
}
|
|
1420
|
+
const validationErrors = this.showValidation
|
|
1421
|
+
? WorkflowValidator.validate(this.workflow)
|
|
1422
|
+
: [];
|
|
1423
|
+
const canvasBounds = SwimlaneLayout.getCanvasBounds(this._positionedNodes);
|
|
1424
|
+
return b `
|
|
1425
|
+
<div class="flow-designer-container">
|
|
1426
|
+
<wc-toolbar
|
|
1427
|
+
class="editor-toolbar"
|
|
1428
|
+
variant="floating"
|
|
1429
|
+
orientation="horizontal"
|
|
1430
|
+
elevated
|
|
1431
|
+
>
|
|
1432
|
+
<wc-icon-button
|
|
1433
|
+
variant="text"
|
|
1434
|
+
?disabled=${this._editor.zoom <= 0.5}
|
|
1435
|
+
@click=${this._handleZoomOut}
|
|
1436
|
+
title="Zoom Out (Ctrl+-)"
|
|
1437
|
+
>
|
|
1438
|
+
<wc-icon name="remove"></wc-icon>
|
|
1439
|
+
</wc-icon-button>
|
|
1440
|
+
<span class="zoom-display">${Math.round(this._editor.zoom * 100)}%</span>
|
|
1441
|
+
<wc-icon-button
|
|
1442
|
+
variant="text"
|
|
1443
|
+
?disabled=${this._editor.zoom >= 2}
|
|
1444
|
+
@click=${this._handleZoomIn}
|
|
1445
|
+
title="Zoom In (Ctrl++)"
|
|
1446
|
+
>
|
|
1447
|
+
<wc-icon name="add"></wc-icon>
|
|
1448
|
+
</wc-icon-button>
|
|
1449
|
+
<wc-icon-button
|
|
1450
|
+
variant="text"
|
|
1451
|
+
?disabled=${!this.canUndo()}
|
|
1452
|
+
@click=${() => this.undo()}
|
|
1453
|
+
title="Undo (Ctrl+Z)"
|
|
1454
|
+
>
|
|
1455
|
+
<wc-icon name="undo"></wc-icon>
|
|
1456
|
+
</wc-icon-button>
|
|
1457
|
+
<wc-icon-button
|
|
1458
|
+
variant="text"
|
|
1459
|
+
?disabled=${!this.canRedo()}
|
|
1460
|
+
@click=${() => this.redo()}
|
|
1461
|
+
title="Redo (Ctrl+Y)"
|
|
1462
|
+
>
|
|
1463
|
+
<wc-icon name="redo"></wc-icon>
|
|
1464
|
+
</wc-icon-button>
|
|
1465
|
+
${!this.readonly
|
|
1466
|
+
? b `
|
|
1467
|
+
<wc-icon-button
|
|
1468
|
+
variant="text"
|
|
1469
|
+
@click=${() => this.validate()}
|
|
1470
|
+
title="Validate Workflow"
|
|
1471
|
+
>
|
|
1472
|
+
<wc-icon name="check_circle"></wc-icon>
|
|
1473
|
+
</wc-icon-button>
|
|
1474
|
+
`
|
|
1475
|
+
: A}
|
|
1476
|
+
</wc-toolbar>
|
|
1477
|
+
|
|
1478
|
+
<!-- Validation messages -->
|
|
1479
|
+
${validationErrors.length > 0
|
|
1480
|
+
? b `
|
|
1481
|
+
<div class="validation-panel">
|
|
1482
|
+
${validationErrors.map((error) => b `
|
|
1483
|
+
<div class="validation-item ${error.severity}">
|
|
1484
|
+
<wc-icon
|
|
1485
|
+
name=${error.severity === 'error' ? 'error' : 'warning'}
|
|
1486
|
+
></wc-icon>
|
|
1487
|
+
<span>${error.message}</span>
|
|
1488
|
+
</div>
|
|
1489
|
+
`)}
|
|
1490
|
+
</div>
|
|
1491
|
+
`
|
|
1492
|
+
: A}
|
|
1493
|
+
|
|
1494
|
+
<!-- Flow canvas -->
|
|
1495
|
+
<div
|
|
1496
|
+
class="flow-designer"
|
|
1497
|
+
@mousedown=${this._handleCanvasMouseDown}
|
|
1498
|
+
@mousemove=${this._handleCanvasMouseMove}
|
|
1499
|
+
>
|
|
1500
|
+
<div
|
|
1501
|
+
class="canvas-container"
|
|
1502
|
+
style="
|
|
1503
|
+
transform: scale(${this._editor.zoom});
|
|
1504
|
+
width: ${canvasBounds.width}px;
|
|
1505
|
+
height: ${canvasBounds.height}px;
|
|
1506
|
+
"
|
|
1507
|
+
>
|
|
1508
|
+
<!-- SVG Connectors -->
|
|
1509
|
+
<svg
|
|
1510
|
+
class="connectors-layer"
|
|
1511
|
+
width="${canvasBounds.width}"
|
|
1512
|
+
height="${canvasBounds.height}"
|
|
1513
|
+
viewBox="0 0 ${canvasBounds.width} ${canvasBounds.height}"
|
|
1514
|
+
>
|
|
1515
|
+
<defs>
|
|
1516
|
+
<marker
|
|
1517
|
+
id="arrowhead"
|
|
1518
|
+
markerWidth="10"
|
|
1519
|
+
markerHeight="10"
|
|
1520
|
+
refX="9"
|
|
1521
|
+
refY="3"
|
|
1522
|
+
orient="auto"
|
|
1523
|
+
>
|
|
1524
|
+
<polygon points="0 0, 10 3, 0 6" fill="currentColor"></polygon>
|
|
1525
|
+
</marker>
|
|
1526
|
+
</defs>
|
|
1527
|
+
${this._renderConnectors()}
|
|
1528
|
+
</svg>
|
|
1529
|
+
|
|
1530
|
+
<!-- Swimlane backgrounds -->
|
|
1531
|
+
<div class="swimlanes-container">
|
|
1532
|
+
${this._renderSwimlanes()}
|
|
1533
|
+
</div>
|
|
1534
|
+
|
|
1535
|
+
<!-- Positioned nodes -->
|
|
1536
|
+
<div class="nodes-layer">
|
|
1537
|
+
${this._renderNodes()}
|
|
1538
|
+
</div>
|
|
1539
|
+
</div>
|
|
1540
|
+
</div>
|
|
1541
|
+
</div>
|
|
1542
|
+
`;
|
|
1543
|
+
}
|
|
1544
|
+
_renderConnectors() {
|
|
1545
|
+
return this._positionedNodes.flatMap((node) => {
|
|
1546
|
+
if (!node.connectorPoints)
|
|
1547
|
+
return [];
|
|
1548
|
+
return node.connectorPoints.map((connector, idx) => {
|
|
1549
|
+
const { from, to, type } = connector;
|
|
1550
|
+
const isLoopback = type === 'curved';
|
|
1551
|
+
if (isLoopback) {
|
|
1552
|
+
// Render curved path for loop back
|
|
1553
|
+
const midY = (from.y + to.y) / 2;
|
|
1554
|
+
const d = `M ${from.x} ${from.y} ` +
|
|
1555
|
+
`L ${from.x + 30} ${from.y} ` +
|
|
1556
|
+
`Q ${from.x + 60} ${midY} ${to.x - 30} ${to.y} ` +
|
|
1557
|
+
`L ${to.x} ${to.y}`;
|
|
1558
|
+
return b `
|
|
1559
|
+
<path
|
|
1560
|
+
key=${`${node.node.id}-connector-${idx}`}
|
|
1561
|
+
d=${d}
|
|
1562
|
+
class="connector ${type}"
|
|
1563
|
+
marker-end="url(#arrowhead)"
|
|
1564
|
+
vector-effect="non-scaling-stroke"
|
|
1565
|
+
></path>
|
|
1566
|
+
`;
|
|
1567
|
+
}
|
|
1568
|
+
// Render straight connector
|
|
1569
|
+
const d = `M ${from.x} ${from.y} L ${to.x} ${to.y}`;
|
|
1570
|
+
return b `
|
|
1571
|
+
<path
|
|
1572
|
+
key=${`${node.node.id}-connector-${idx}`}
|
|
1573
|
+
d=${d}
|
|
1574
|
+
class="connector ${type}"
|
|
1575
|
+
marker-end="url(#arrowhead)"
|
|
1576
|
+
vector-effect="non-scaling-stroke"
|
|
1577
|
+
></path>
|
|
1578
|
+
`;
|
|
1579
|
+
});
|
|
1580
|
+
});
|
|
1581
|
+
}
|
|
1582
|
+
_renderSwimlanes() {
|
|
1583
|
+
const swimlanes = SwimlaneLayout.getSwimlanes(this._positionedNodes);
|
|
1584
|
+
return swimlanes.map((lane) => {
|
|
1585
|
+
const laneTop = Math.min(...lane.nodes.map((n) => n.y)) - 14;
|
|
1586
|
+
const laneBottom = Math.max(...lane.nodes.map((n) => n.y + n.height)) + 14;
|
|
1587
|
+
const laneHeight = Math.max(120, laneBottom - laneTop);
|
|
1588
|
+
return b `
|
|
1589
|
+
<div
|
|
1590
|
+
class="swimlane ${lane.isParallel ? 'parallel' : ''}"
|
|
1591
|
+
style="top: ${laneTop}px; height: ${laneHeight}px;"
|
|
1592
|
+
>
|
|
1593
|
+
<div class="swimlane-header">${lane.name}</div>
|
|
1594
|
+
</div>
|
|
1595
|
+
`;
|
|
1596
|
+
});
|
|
1597
|
+
}
|
|
1598
|
+
_renderNodes() {
|
|
1599
|
+
return this._positionedNodes.map((posNode) => b `
|
|
1600
|
+
<div
|
|
1601
|
+
class="positioned-node"
|
|
1602
|
+
style="
|
|
1603
|
+
left: ${posNode.x}px;
|
|
1604
|
+
top: ${posNode.y}px;
|
|
1605
|
+
width: ${posNode.width}px;
|
|
1606
|
+
height: ${posNode.height}px;
|
|
1607
|
+
"
|
|
1608
|
+
>
|
|
1609
|
+
<wc-flow-designer-node
|
|
1610
|
+
.node=${posNode.node}
|
|
1611
|
+
?selected=${posNode.node.id === this._editor.selectedNodeId}
|
|
1612
|
+
?editing=${this._editor.isEditing &&
|
|
1613
|
+
posNode.node.id === this._editor.selectedNodeId}
|
|
1614
|
+
?disabled=${this.disabled}
|
|
1615
|
+
@node-click=${this._handleNodeClick}
|
|
1616
|
+
@node-delete=${this._handleNodeDelete}
|
|
1617
|
+
@node-edit-start=${this._handleNodeEdit}
|
|
1618
|
+
></wc-flow-designer-node>
|
|
1619
|
+
</div>
|
|
1620
|
+
`);
|
|
1621
|
+
}
|
|
1622
|
+
};
|
|
1623
|
+
FlowDesigner.styles = [css_248z$1];
|
|
1624
|
+
__decorate([
|
|
1625
|
+
n({ type: Object })
|
|
1626
|
+
], FlowDesigner.prototype, "workflow", void 0);
|
|
1627
|
+
__decorate([
|
|
1628
|
+
n({ type: Boolean, reflect: true, attribute: 'readonly' })
|
|
1629
|
+
], FlowDesigner.prototype, "readonly", void 0);
|
|
1630
|
+
__decorate([
|
|
1631
|
+
n({ type: Boolean, reflect: true })
|
|
1632
|
+
], FlowDesigner.prototype, "disabled", void 0);
|
|
1633
|
+
__decorate([
|
|
1634
|
+
n({ type: Boolean, attribute: 'show-validation' })
|
|
1635
|
+
], FlowDesigner.prototype, "showValidation", void 0);
|
|
1636
|
+
__decorate([
|
|
1637
|
+
r()
|
|
1638
|
+
], FlowDesigner.prototype, "_editor", void 0);
|
|
1639
|
+
__decorate([
|
|
1640
|
+
r()
|
|
1641
|
+
], FlowDesigner.prototype, "_positionedNodes", void 0);
|
|
1642
|
+
__decorate([
|
|
1643
|
+
r()
|
|
1644
|
+
], FlowDesigner.prototype, "_history", void 0);
|
|
1645
|
+
__decorate([
|
|
1646
|
+
r()
|
|
1647
|
+
], FlowDesigner.prototype, "_historyIndex", void 0);
|
|
1648
|
+
__decorate([
|
|
1649
|
+
e$2('.flow-designer')
|
|
1650
|
+
], FlowDesigner.prototype, "scrollElm", void 0);
|
|
1651
|
+
FlowDesigner = __decorate([
|
|
1652
|
+
IndividualComponent
|
|
1653
|
+
], FlowDesigner);
|
|
1654
|
+
|
|
1655
|
+
export { FlowDesigner as F, Icon as I, fetchSVG as f, o, sanitizeSvg as s };
|
|
1656
|
+
//# sourceMappingURL=flow-designer-DvTUrDp5.js.map
|