@bpmn-nova/studio 0.4.0 → 0.4.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/README.md +1 -1
- package/dist/flow-tree.d.ts +4 -0
- package/dist/flow-tree.js +14 -0
- package/dist/modules/flow-tree/controller.js +364 -0
- package/dist/modules/flow-tree/index.d.ts +248 -0
- package/dist/modules/flow-tree/index.js +5 -0
- package/dist/modules/flow-tree/operations.js +484 -0
- package/dist/modules/flow-tree/sample.js +445 -0
- package/dist/modules/flow-tree/schema.js +588 -0
- package/dist/modules/flow-tree/validate.js +125 -0
- package/dist/modules/flow-tree-bpmn/compiler.js +547 -0
- package/dist/modules/flow-tree-bpmn/decompiler.js +524 -0
- package/dist/modules/flow-tree-bpmn/expression.js +135 -0
- package/dist/modules/flow-tree-bpmn/index.d.ts +53 -0
- package/dist/modules/flow-tree-bpmn/index.js +14 -0
- package/dist/modules/flow-tree-renderer/canvas.js +1003 -0
- package/dist/modules/flow-tree-renderer/export-svg.js +325 -0
- package/dist/modules/flow-tree-renderer/index.d.ts +143 -0
- package/dist/modules/flow-tree-renderer/index.js +3 -0
- package/dist/modules/flow-tree-renderer/shell.js +970 -0
- package/dist/modules/i18n/locales/en-US.js +399 -0
- package/dist/modules/i18n/locales/zh-CN.js +399 -0
- package/dist/modules/icons/index.js +23 -0
- package/dist/modules/properties-flow-tree/index.d.ts +56 -0
- package/dist/modules/properties-flow-tree/index.js +2 -0
- package/dist/modules/properties-flow-tree/panel.js +1136 -0
- package/dist/modules/properties-flow-tree/widgets.js +625 -0
- package/dist/modules/viewer/index.js +10 -2
- package/dist/styles.css +2368 -0
- package/llms-full.txt +353 -9
- package/llms.txt +3 -2
- package/package.json +6 -1
|
@@ -0,0 +1,625 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CONDITION_OPERATORS,
|
|
3
|
+
cloneFlowTree,
|
|
4
|
+
createEmptyConditionGroup,
|
|
5
|
+
createEmptyConditionRule,
|
|
6
|
+
} from '../flow-tree/index.js';
|
|
7
|
+
import { compileConditionGroups } from '../flow-tree-bpmn/index.js';
|
|
8
|
+
|
|
9
|
+
export function dom(tag, className = '', text = undefined) {
|
|
10
|
+
const el = document.createElement(tag);
|
|
11
|
+
if (className) el.className = className;
|
|
12
|
+
if (text !== undefined) el.textContent = text;
|
|
13
|
+
return el;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function iconSpan(id, className = 'nova-icon nova-icon-sm') {
|
|
17
|
+
const span = dom('span', className);
|
|
18
|
+
span.dataset.icon = id;
|
|
19
|
+
return span;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function createSection(title, description = '') {
|
|
23
|
+
const section = dom('section', 'ft-prop-section');
|
|
24
|
+
if (title) {
|
|
25
|
+
const heading = dom('div', 'ft-prop-section-head');
|
|
26
|
+
heading.appendChild(dom('strong', '', title));
|
|
27
|
+
section.appendChild(heading);
|
|
28
|
+
}
|
|
29
|
+
if (description) section.appendChild(dom('p', 'ft-prop-section-desc', description));
|
|
30
|
+
const body = dom('div', 'ft-prop-section-body');
|
|
31
|
+
section.appendChild(body);
|
|
32
|
+
return { section, body };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function createField(label, control, { note = '', required = false } = {}) {
|
|
36
|
+
const wrapper = dom('div', 'ft-prop-field');
|
|
37
|
+
if (label) {
|
|
38
|
+
const labelEl = dom('label', 'ft-prop-label');
|
|
39
|
+
labelEl.appendChild(document.createTextNode(label));
|
|
40
|
+
if (required) labelEl.appendChild(dom('span', 'ft-prop-required', ' *'));
|
|
41
|
+
wrapper.appendChild(labelEl);
|
|
42
|
+
}
|
|
43
|
+
wrapper.appendChild(control);
|
|
44
|
+
if (note) wrapper.appendChild(dom('div', 'ft-prop-note', note));
|
|
45
|
+
return wrapper;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function createTextInput({ value = '', placeholder = '', disabled = false, monospace = false, onChange }) {
|
|
49
|
+
const input = dom('input', `ft-prop-input${monospace ? ' is-mono' : ''}`);
|
|
50
|
+
input.type = 'text';
|
|
51
|
+
input.value = value ?? '';
|
|
52
|
+
if (placeholder) input.placeholder = placeholder;
|
|
53
|
+
input.disabled = Boolean(disabled);
|
|
54
|
+
input.addEventListener('change', () => onChange?.(input.value));
|
|
55
|
+
input.addEventListener('keydown', (event) => {
|
|
56
|
+
if (event.key === 'Enter') {
|
|
57
|
+
event.preventDefault();
|
|
58
|
+
input.blur();
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return input;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function createNumberInput({ value = 1, min = 0, max = undefined, step = 1, disabled = false, onChange }) {
|
|
65
|
+
const input = dom('input', 'ft-prop-input');
|
|
66
|
+
input.type = 'number';
|
|
67
|
+
input.value = value ?? '';
|
|
68
|
+
if (min !== undefined) input.min = String(min);
|
|
69
|
+
if (max !== undefined) input.max = String(max);
|
|
70
|
+
input.step = String(step);
|
|
71
|
+
input.disabled = Boolean(disabled);
|
|
72
|
+
input.addEventListener('change', () => onChange?.(Number(input.value)));
|
|
73
|
+
input.addEventListener('keydown', (event) => {
|
|
74
|
+
if (event.key === 'Enter') {
|
|
75
|
+
event.preventDefault();
|
|
76
|
+
input.blur();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
return input;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function createTextarea({ value = '', rows = 3, placeholder = '', monospace = false, disabled = false, onChange }) {
|
|
83
|
+
const area = dom('textarea', `ft-prop-textarea${monospace ? ' is-mono' : ''}`);
|
|
84
|
+
area.rows = rows;
|
|
85
|
+
area.value = value ?? '';
|
|
86
|
+
if (placeholder) area.placeholder = placeholder;
|
|
87
|
+
area.disabled = Boolean(disabled);
|
|
88
|
+
area.addEventListener('change', () => onChange?.(area.value));
|
|
89
|
+
return area;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function createSelect({ value = '', options = [], disabled = false, onChange }) {
|
|
93
|
+
const select = dom('select', 'ft-prop-select');
|
|
94
|
+
select.disabled = Boolean(disabled);
|
|
95
|
+
for (const option of options) {
|
|
96
|
+
const opt = document.createElement('option');
|
|
97
|
+
opt.value = String(option.value);
|
|
98
|
+
opt.textContent = option.label;
|
|
99
|
+
if (String(option.value) === String(value ?? '')) opt.selected = true;
|
|
100
|
+
select.appendChild(opt);
|
|
101
|
+
}
|
|
102
|
+
select.addEventListener('change', () => onChange?.(select.value));
|
|
103
|
+
return select;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function createSwitch({ checked = false, label = '', onChange }) {
|
|
107
|
+
const button = dom('button', `ft-prop-switch${checked ? ' is-on' : ''}`);
|
|
108
|
+
button.type = 'button';
|
|
109
|
+
button.setAttribute('aria-pressed', checked ? 'true' : 'false');
|
|
110
|
+
button.append(dom('span', 'ft-prop-switch-track'), dom('strong', '', label));
|
|
111
|
+
button.addEventListener('click', () => onChange?.(!checked));
|
|
112
|
+
return button;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function resolveProviderItems(provider, query = '') {
|
|
116
|
+
if (!provider) return [];
|
|
117
|
+
const fn = provider.search || provider.list;
|
|
118
|
+
if (typeof fn !== 'function') return [];
|
|
119
|
+
const raw = await fn.call(provider, query);
|
|
120
|
+
if (!Array.isArray(raw)) return [];
|
|
121
|
+
return raw.map((item) => {
|
|
122
|
+
if (typeof item === 'string') return { id: item, name: item };
|
|
123
|
+
return {
|
|
124
|
+
id: String(item.id ?? item.value ?? item.key ?? ''),
|
|
125
|
+
name: String(item.name ?? item.label ?? item.id ?? ''),
|
|
126
|
+
};
|
|
127
|
+
}).filter((item) => item.id);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function createTargetPicker({ value = [], provider = null, i18n, onChange }) {
|
|
131
|
+
const t = (key, params) => i18n.t(key, params);
|
|
132
|
+
const current = Array.isArray(value) ? value.map((item) => typeof item === 'string' ? { id: item, name: item } : { id: item.id, name: item.name || item.id }) : [];
|
|
133
|
+
const root = dom('div', 'ft-picker');
|
|
134
|
+
|
|
135
|
+
const chips = dom('div', 'ft-picker-chips');
|
|
136
|
+
if (!current.length) {
|
|
137
|
+
chips.appendChild(dom('span', 'ft-picker-empty', t('flowTree.properties.picker.emptyHint')));
|
|
138
|
+
} else {
|
|
139
|
+
for (const item of current) {
|
|
140
|
+
const chip = dom('span', 'ft-picker-chip');
|
|
141
|
+
chip.appendChild(dom('span', '', item.name));
|
|
142
|
+
const remove = dom('button', 'ft-picker-chip-remove');
|
|
143
|
+
remove.type = 'button';
|
|
144
|
+
remove.setAttribute('aria-label', item.name);
|
|
145
|
+
remove.appendChild(iconSpan('ui.close', 'nova-icon nova-icon-xs'));
|
|
146
|
+
remove.addEventListener('click', () => {
|
|
147
|
+
onChange?.(current.filter((candidate) => candidate.id !== item.id));
|
|
148
|
+
});
|
|
149
|
+
chip.appendChild(remove);
|
|
150
|
+
chips.appendChild(chip);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
root.appendChild(chips);
|
|
154
|
+
|
|
155
|
+
const controls = dom('div', 'ft-picker-controls');
|
|
156
|
+
const input = dom('input', 'ft-prop-input');
|
|
157
|
+
input.type = 'text';
|
|
158
|
+
input.placeholder = t('flowTree.properties.picker.searchPlaceholder');
|
|
159
|
+
const addBtn = dom('button', 'ft-prop-mini-btn', t('flowTree.properties.picker.addButton'));
|
|
160
|
+
addBtn.type = 'button';
|
|
161
|
+
controls.append(input, addBtn);
|
|
162
|
+
root.appendChild(controls);
|
|
163
|
+
|
|
164
|
+
const dropdown = dom('div', 'ft-picker-dropdown');
|
|
165
|
+
dropdown.hidden = true;
|
|
166
|
+
root.appendChild(dropdown);
|
|
167
|
+
|
|
168
|
+
const addItem = (item) => {
|
|
169
|
+
const id = String(item?.id || '').trim();
|
|
170
|
+
if (!id || current.some((existing) => existing.id === id)) return;
|
|
171
|
+
onChange?.([...current, { id, name: String(item?.name || id).trim() }]);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
let queryToken = 0;
|
|
175
|
+
const loadSuggestions = async (query) => {
|
|
176
|
+
if (!provider) {
|
|
177
|
+
dropdown.hidden = true;
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const token = ++queryToken;
|
|
181
|
+
dropdown.hidden = false;
|
|
182
|
+
dropdown.replaceChildren(dom('div', 'ft-picker-status', t('flowTree.properties.picker.loading')));
|
|
183
|
+
try {
|
|
184
|
+
const list = await resolveProviderItems(provider, query);
|
|
185
|
+
if (token !== queryToken) return;
|
|
186
|
+
const available = list.filter((item) => !current.some((existing) => existing.id === item.id));
|
|
187
|
+
dropdown.replaceChildren();
|
|
188
|
+
if (!available.length) {
|
|
189
|
+
dropdown.hidden = true;
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
for (const item of available.slice(0, 12)) {
|
|
193
|
+
const opt = dom('button', 'ft-picker-option');
|
|
194
|
+
opt.type = 'button';
|
|
195
|
+
opt.append(dom('strong', '', item.name), dom('small', '', item.id));
|
|
196
|
+
opt.addEventListener('mousedown', (event) => {
|
|
197
|
+
event.preventDefault();
|
|
198
|
+
addItem(item);
|
|
199
|
+
dropdown.hidden = true;
|
|
200
|
+
});
|
|
201
|
+
dropdown.appendChild(opt);
|
|
202
|
+
}
|
|
203
|
+
} catch {
|
|
204
|
+
if (token === queryToken) dropdown.hidden = true;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
input.addEventListener('focus', () => loadSuggestions(input.value));
|
|
209
|
+
input.addEventListener('input', () => loadSuggestions(input.value));
|
|
210
|
+
input.addEventListener('blur', () => {
|
|
211
|
+
setTimeout(() => { dropdown.hidden = true; }, 120);
|
|
212
|
+
});
|
|
213
|
+
input.addEventListener('keydown', (event) => {
|
|
214
|
+
if (event.key === 'Enter') {
|
|
215
|
+
event.preventDefault();
|
|
216
|
+
const raw = input.value.trim();
|
|
217
|
+
if (raw) addItem({ id: raw, name: raw });
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
addBtn.addEventListener('click', () => {
|
|
221
|
+
const raw = input.value.trim();
|
|
222
|
+
if (raw) addItem({ id: raw, name: raw });
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
return root;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export function createConditionBuilder({ groups = [], formFields = [], i18n, onChange }) {
|
|
229
|
+
const t = (key, params) => i18n.t(key, params);
|
|
230
|
+
const root = dom('div', 'ft-cond-builder');
|
|
231
|
+
const currentGroups = Array.isArray(groups) && groups.length
|
|
232
|
+
? cloneFlowTree(groups)
|
|
233
|
+
: [];
|
|
234
|
+
|
|
235
|
+
const emit = (next) => onChange?.(next);
|
|
236
|
+
|
|
237
|
+
const hint = dom('div', 'ft-cond-hint', t('flowTree.properties.condition.outerOrHint'));
|
|
238
|
+
root.appendChild(hint);
|
|
239
|
+
|
|
240
|
+
currentGroups.forEach((group, groupIndex) => {
|
|
241
|
+
if (groupIndex > 0) {
|
|
242
|
+
root.appendChild(dom('div', 'ft-cond-or-divider', 'OR'));
|
|
243
|
+
}
|
|
244
|
+
const card = dom('div', 'ft-cond-group');
|
|
245
|
+
const head = dom('div', 'ft-cond-group-head');
|
|
246
|
+
const logicSelect = createSelect({
|
|
247
|
+
value: group.logic || 'AND',
|
|
248
|
+
options: [
|
|
249
|
+
{ value: 'AND', label: t('flowTree.properties.condition.groupLogicAnd') },
|
|
250
|
+
{ value: 'OR', label: t('flowTree.properties.condition.groupLogicOr') },
|
|
251
|
+
],
|
|
252
|
+
onChange: (nextLogic) => {
|
|
253
|
+
const copy = cloneFlowTree(currentGroups);
|
|
254
|
+
copy[groupIndex].logic = nextLogic;
|
|
255
|
+
emit(copy);
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
const removeGroupBtn = dom('button', 'ft-icon-btn is-danger');
|
|
259
|
+
removeGroupBtn.type = 'button';
|
|
260
|
+
removeGroupBtn.title = t('flowTree.properties.condition.removeGroup');
|
|
261
|
+
removeGroupBtn.appendChild(iconSpan('ui.delete', 'nova-icon nova-icon-xs'));
|
|
262
|
+
removeGroupBtn.addEventListener('click', () => {
|
|
263
|
+
const copy = cloneFlowTree(currentGroups);
|
|
264
|
+
copy.splice(groupIndex, 1);
|
|
265
|
+
emit(copy);
|
|
266
|
+
});
|
|
267
|
+
head.append(logicSelect, removeGroupBtn);
|
|
268
|
+
card.appendChild(head);
|
|
269
|
+
|
|
270
|
+
const rulesHost = dom('div', 'ft-cond-rules');
|
|
271
|
+
(group.rules || []).forEach((rule, ruleIndex) => {
|
|
272
|
+
const ruleRow = dom('div', 'ft-cond-rule');
|
|
273
|
+
const matchedSchema = formFields.find((f) => f.key === rule.field) || null;
|
|
274
|
+
const fieldType = matchedSchema?.type || rule.fieldType || 'string';
|
|
275
|
+
|
|
276
|
+
// Field selector or free input
|
|
277
|
+
let fieldControl;
|
|
278
|
+
if (formFields.length) {
|
|
279
|
+
const options = [
|
|
280
|
+
{ value: '', label: t('flowTree.properties.condition.fieldPlaceholder') },
|
|
281
|
+
...formFields.map((field) => ({ value: field.key, label: `${field.label} (${field.key})` })),
|
|
282
|
+
...(rule.field && !matchedSchema ? [{ value: rule.field, label: rule.field }] : []),
|
|
283
|
+
];
|
|
284
|
+
fieldControl = createSelect({
|
|
285
|
+
value: rule.field || '',
|
|
286
|
+
options,
|
|
287
|
+
onChange: (nextKey) => {
|
|
288
|
+
const copy = cloneFlowTree(currentGroups);
|
|
289
|
+
const schema = formFields.find((f) => f.key === nextKey);
|
|
290
|
+
copy[groupIndex].rules[ruleIndex].field = nextKey;
|
|
291
|
+
copy[groupIndex].rules[ruleIndex].fieldLabel = schema?.label || nextKey;
|
|
292
|
+
copy[groupIndex].rules[ruleIndex].fieldType = schema?.type || 'string';
|
|
293
|
+
emit(copy);
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
} else {
|
|
297
|
+
fieldControl = createTextInput({
|
|
298
|
+
value: rule.field || '',
|
|
299
|
+
placeholder: t('flowTree.properties.condition.fieldPlaceholder'),
|
|
300
|
+
onChange: (nextKey) => {
|
|
301
|
+
const copy = cloneFlowTree(currentGroups);
|
|
302
|
+
copy[groupIndex].rules[ruleIndex].field = nextKey.trim();
|
|
303
|
+
copy[groupIndex].rules[ruleIndex].fieldLabel = nextKey.trim();
|
|
304
|
+
emit(copy);
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const opList = CONDITION_OPERATORS.filter((op) => !formFields.length || !matchedSchema || op.types.includes(fieldType));
|
|
310
|
+
const validOp = opList.some((op) => op.value === rule.operator) ? rule.operator : (opList[0]?.value || 'eq');
|
|
311
|
+
const opMeta = CONDITION_OPERATORS.find((op) => op.value === validOp) || CONDITION_OPERATORS[0];
|
|
312
|
+
|
|
313
|
+
const opSelect = createSelect({
|
|
314
|
+
value: validOp,
|
|
315
|
+
options: opList.map((op) => ({
|
|
316
|
+
value: op.value,
|
|
317
|
+
label: t(`flowTree.properties.condition.operators.${op.value}`),
|
|
318
|
+
})),
|
|
319
|
+
onChange: (nextOp) => {
|
|
320
|
+
const copy = cloneFlowTree(currentGroups);
|
|
321
|
+
copy[groupIndex].rules[ruleIndex].operator = nextOp;
|
|
322
|
+
emit(copy);
|
|
323
|
+
},
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
const removeRuleBtn = dom('button', 'ft-icon-btn is-danger');
|
|
327
|
+
removeRuleBtn.type = 'button';
|
|
328
|
+
removeRuleBtn.title = t('flowTree.properties.condition.removeRule');
|
|
329
|
+
removeRuleBtn.appendChild(iconSpan('ui.close', 'nova-icon nova-icon-xs'));
|
|
330
|
+
removeRuleBtn.addEventListener('click', () => {
|
|
331
|
+
const copy = cloneFlowTree(currentGroups);
|
|
332
|
+
copy[groupIndex].rules.splice(ruleIndex, 1);
|
|
333
|
+
if (!copy[groupIndex].rules.length) copy.splice(groupIndex, 1);
|
|
334
|
+
emit(copy);
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
const topLine = dom('div', 'ft-cond-rule-top');
|
|
338
|
+
topLine.append(fieldControl, opSelect, removeRuleBtn);
|
|
339
|
+
ruleRow.appendChild(topLine);
|
|
340
|
+
|
|
341
|
+
if (!opMeta.unary) {
|
|
342
|
+
const valueRow = dom('div', 'ft-cond-rule-value');
|
|
343
|
+
if (opMeta.range) {
|
|
344
|
+
const minInput = createTextInput({
|
|
345
|
+
value: rule.value ?? '',
|
|
346
|
+
placeholder: t('flowTree.properties.condition.minPlaceholder'),
|
|
347
|
+
onChange: (nextVal) => {
|
|
348
|
+
const copy = cloneFlowTree(currentGroups);
|
|
349
|
+
copy[groupIndex].rules[ruleIndex].value = nextVal;
|
|
350
|
+
emit(copy);
|
|
351
|
+
},
|
|
352
|
+
});
|
|
353
|
+
const maxInput = createTextInput({
|
|
354
|
+
value: rule.valueMax ?? '',
|
|
355
|
+
placeholder: t('flowTree.properties.condition.maxPlaceholder'),
|
|
356
|
+
onChange: (nextVal) => {
|
|
357
|
+
const copy = cloneFlowTree(currentGroups);
|
|
358
|
+
copy[groupIndex].rules[ruleIndex].valueMax = nextVal;
|
|
359
|
+
emit(copy);
|
|
360
|
+
},
|
|
361
|
+
});
|
|
362
|
+
valueRow.classList.add('is-range');
|
|
363
|
+
valueRow.append(minInput, dom('span', 'ft-cond-range-sep', '~'), maxInput);
|
|
364
|
+
} else if (matchedSchema?.options?.length && !opMeta.multi) {
|
|
365
|
+
valueRow.appendChild(createSelect({
|
|
366
|
+
value: rule.value ?? '',
|
|
367
|
+
options: [
|
|
368
|
+
{ value: '', label: t('flowTree.properties.condition.valuePlaceholder') },
|
|
369
|
+
...matchedSchema.options.map((item) => ({ value: item.value ?? item.id, label: item.label ?? item.name ?? item.value })),
|
|
370
|
+
],
|
|
371
|
+
onChange: (nextVal) => {
|
|
372
|
+
const copy = cloneFlowTree(currentGroups);
|
|
373
|
+
copy[groupIndex].rules[ruleIndex].value = nextVal;
|
|
374
|
+
emit(copy);
|
|
375
|
+
},
|
|
376
|
+
}));
|
|
377
|
+
} else {
|
|
378
|
+
valueRow.appendChild(createTextInput({
|
|
379
|
+
value: rule.value ?? '',
|
|
380
|
+
placeholder: t('flowTree.properties.condition.valuePlaceholder'),
|
|
381
|
+
onChange: (nextVal) => {
|
|
382
|
+
const copy = cloneFlowTree(currentGroups);
|
|
383
|
+
copy[groupIndex].rules[ruleIndex].value = nextVal;
|
|
384
|
+
emit(copy);
|
|
385
|
+
},
|
|
386
|
+
}));
|
|
387
|
+
}
|
|
388
|
+
ruleRow.appendChild(valueRow);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
rulesHost.appendChild(ruleRow);
|
|
392
|
+
});
|
|
393
|
+
card.appendChild(rulesHost);
|
|
394
|
+
|
|
395
|
+
const addRuleBtn = dom('button', 'ft-prop-dashed-btn');
|
|
396
|
+
addRuleBtn.type = 'button';
|
|
397
|
+
addRuleBtn.append(iconSpan('ui.add', 'nova-icon nova-icon-xs'), dom('span', '', t('flowTree.properties.condition.addRule')));
|
|
398
|
+
addRuleBtn.addEventListener('click', () => {
|
|
399
|
+
const copy = cloneFlowTree(currentGroups);
|
|
400
|
+
const firstField = formFields[0];
|
|
401
|
+
copy[groupIndex].rules.push(createEmptyConditionRule({
|
|
402
|
+
field: firstField?.key || '',
|
|
403
|
+
fieldLabel: firstField?.label || '',
|
|
404
|
+
fieldType: firstField?.type || 'string',
|
|
405
|
+
}));
|
|
406
|
+
emit(copy);
|
|
407
|
+
});
|
|
408
|
+
card.appendChild(addRuleBtn);
|
|
409
|
+
root.appendChild(card);
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
const addGroupBtn = dom('button', 'ft-prop-action-btn');
|
|
413
|
+
addGroupBtn.type = 'button';
|
|
414
|
+
addGroupBtn.append(iconSpan('ui.add', 'nova-icon nova-icon-xs'), dom('span', '', t('flowTree.properties.condition.addGroup')));
|
|
415
|
+
addGroupBtn.addEventListener('click', () => {
|
|
416
|
+
const firstField = formFields[0];
|
|
417
|
+
const copy = cloneFlowTree(currentGroups);
|
|
418
|
+
copy.push(createEmptyConditionGroup({
|
|
419
|
+
rules: [createEmptyConditionRule({
|
|
420
|
+
field: firstField?.key || '',
|
|
421
|
+
fieldLabel: firstField?.label || '',
|
|
422
|
+
fieldType: firstField?.type || 'string',
|
|
423
|
+
})],
|
|
424
|
+
}));
|
|
425
|
+
emit(copy);
|
|
426
|
+
});
|
|
427
|
+
root.appendChild(addGroupBtn);
|
|
428
|
+
|
|
429
|
+
// Live JUEL preview
|
|
430
|
+
const compiled = compileConditionGroups(currentGroups);
|
|
431
|
+
const preview = dom('div', 'ft-cond-preview');
|
|
432
|
+
preview.append(
|
|
433
|
+
dom('small', '', t('flowTree.properties.sections.conditionPreview')),
|
|
434
|
+
dom('code', '', compiled || t('flowTree.properties.condition.noExpressionYet')),
|
|
435
|
+
);
|
|
436
|
+
root.appendChild(preview);
|
|
437
|
+
|
|
438
|
+
return root;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
export function createFormPermissionMatrix({ permissions = {}, formFields = [], allowEditable = true, i18n, onChange }) {
|
|
442
|
+
const t = (key, params) => i18n.t(key, params);
|
|
443
|
+
const root = dom('div', 'ft-perm-matrix');
|
|
444
|
+
const modes = allowEditable
|
|
445
|
+
? [
|
|
446
|
+
{ value: 'editable', label: t('flowTree.properties.options.permEditable') },
|
|
447
|
+
{ value: 'readonly', label: t('flowTree.properties.options.permReadonly') },
|
|
448
|
+
{ value: 'hidden', label: t('flowTree.properties.options.permHidden') },
|
|
449
|
+
]
|
|
450
|
+
: [
|
|
451
|
+
{ value: 'readonly', label: t('flowTree.properties.options.permReadonly') },
|
|
452
|
+
{ value: 'hidden', label: t('flowTree.properties.options.permHidden') },
|
|
453
|
+
];
|
|
454
|
+
const defaultMode = allowEditable ? 'readonly' : 'readonly';
|
|
455
|
+
|
|
456
|
+
const currentPerms = { ...(permissions || {}) };
|
|
457
|
+
const fieldMap = new Map();
|
|
458
|
+
for (const field of formFields || []) {
|
|
459
|
+
if (field?.key) fieldMap.set(field.key, { key: field.key, label: field.label || field.key });
|
|
460
|
+
}
|
|
461
|
+
for (const key of Object.keys(currentPerms)) {
|
|
462
|
+
if (!fieldMap.has(key)) fieldMap.set(key, { key, label: key });
|
|
463
|
+
}
|
|
464
|
+
const rows = [...fieldMap.values()];
|
|
465
|
+
|
|
466
|
+
if (rows.length) {
|
|
467
|
+
const table = dom('div', `ft-perm-table cols-${modes.length}`);
|
|
468
|
+
const head = dom('div', 'ft-perm-head');
|
|
469
|
+
head.appendChild(dom('span', '', t('flowTree.properties.formMatrix.fieldColumn')));
|
|
470
|
+
for (const mode of modes) {
|
|
471
|
+
const colBtn = dom('button', 'ft-perm-col-btn');
|
|
472
|
+
colBtn.type = 'button';
|
|
473
|
+
colBtn.title = `${t('flowTree.properties.formMatrix.batchAll')} ${mode.label}`;
|
|
474
|
+
colBtn.textContent = mode.label;
|
|
475
|
+
colBtn.addEventListener('click', () => {
|
|
476
|
+
const next = { ...currentPerms };
|
|
477
|
+
for (const row of rows) next[row.key] = mode.value;
|
|
478
|
+
onChange?.(next);
|
|
479
|
+
});
|
|
480
|
+
head.appendChild(colBtn);
|
|
481
|
+
}
|
|
482
|
+
table.appendChild(head);
|
|
483
|
+
|
|
484
|
+
for (const row of rows) {
|
|
485
|
+
const currentValue = currentPerms[row.key] || defaultMode;
|
|
486
|
+
const line = dom('div', 'ft-perm-row');
|
|
487
|
+
const nameCell = dom('div', 'ft-perm-field-name');
|
|
488
|
+
nameCell.append(dom('strong', '', row.label), dom('small', '', row.key));
|
|
489
|
+
line.appendChild(nameCell);
|
|
490
|
+
for (const mode of modes) {
|
|
491
|
+
const radioWrap = dom('label', 'ft-perm-cell');
|
|
492
|
+
const radio = document.createElement('input');
|
|
493
|
+
radio.type = 'radio';
|
|
494
|
+
radio.name = `ft-perm-${row.key}-${Math.random().toString(36).slice(2, 6)}`;
|
|
495
|
+
radio.checked = currentValue === mode.value;
|
|
496
|
+
radio.addEventListener('change', () => {
|
|
497
|
+
onChange?.({ ...currentPerms, [row.key]: mode.value });
|
|
498
|
+
});
|
|
499
|
+
radioWrap.appendChild(radio);
|
|
500
|
+
line.appendChild(radioWrap);
|
|
501
|
+
}
|
|
502
|
+
table.appendChild(line);
|
|
503
|
+
}
|
|
504
|
+
root.appendChild(table);
|
|
505
|
+
} else {
|
|
506
|
+
root.appendChild(dom('div', 'ft-prop-empty-box', t('flowTree.properties.formMatrix.emptyFields')));
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
const addBar = dom('div', 'ft-picker-controls');
|
|
510
|
+
const keyInput = dom('input', 'ft-prop-input');
|
|
511
|
+
keyInput.type = 'text';
|
|
512
|
+
keyInput.placeholder = t('flowTree.properties.formMatrix.addFieldPlaceholder');
|
|
513
|
+
const addBtn = dom('button', 'ft-prop-mini-btn', t('flowTree.properties.formMatrix.addFieldButton'));
|
|
514
|
+
addBtn.type = 'button';
|
|
515
|
+
const commitField = () => {
|
|
516
|
+
const key = keyInput.value.trim();
|
|
517
|
+
if (!key) return;
|
|
518
|
+
onChange?.({ ...currentPerms, [key]: currentPerms[key] || defaultMode });
|
|
519
|
+
};
|
|
520
|
+
addBtn.addEventListener('click', commitField);
|
|
521
|
+
keyInput.addEventListener('keydown', (event) => {
|
|
522
|
+
if (event.key === 'Enter') { event.preventDefault(); commitField(); }
|
|
523
|
+
});
|
|
524
|
+
addBar.append(keyInput, addBtn);
|
|
525
|
+
root.appendChild(addBar);
|
|
526
|
+
|
|
527
|
+
return root;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
export function createKeyValueTable({ rows = [], columns = [], addLabel = 'Add', onChange }) {
|
|
531
|
+
const current = Array.isArray(rows) ? cloneFlowTree(rows) : [];
|
|
532
|
+
const root = dom('div', 'ft-kv-table');
|
|
533
|
+
|
|
534
|
+
if (current.length) {
|
|
535
|
+
const head = dom('div', 'ft-kv-head');
|
|
536
|
+
head.style.setProperty('--ft-kv-cols', String(columns.length));
|
|
537
|
+
for (const col of columns) head.appendChild(dom('span', '', col.label));
|
|
538
|
+
head.appendChild(dom('span', '', ''));
|
|
539
|
+
root.appendChild(head);
|
|
540
|
+
|
|
541
|
+
current.forEach((row, rowIndex) => {
|
|
542
|
+
const line = dom('div', 'ft-kv-row');
|
|
543
|
+
line.style.setProperty('--ft-kv-cols', String(columns.length));
|
|
544
|
+
for (const col of columns) {
|
|
545
|
+
const input = dom('input', 'ft-prop-input is-compact');
|
|
546
|
+
input.type = 'text';
|
|
547
|
+
input.value = row?.[col.key] ?? '';
|
|
548
|
+
input.placeholder = col.placeholder || '';
|
|
549
|
+
input.addEventListener('change', () => {
|
|
550
|
+
const copy = cloneFlowTree(current);
|
|
551
|
+
copy[rowIndex][col.key] = input.value;
|
|
552
|
+
onChange?.(copy);
|
|
553
|
+
});
|
|
554
|
+
line.appendChild(input);
|
|
555
|
+
}
|
|
556
|
+
const removeBtn = dom('button', 'ft-icon-btn is-danger');
|
|
557
|
+
removeBtn.type = 'button';
|
|
558
|
+
removeBtn.appendChild(iconSpan('ui.delete', 'nova-icon nova-icon-xs'));
|
|
559
|
+
removeBtn.addEventListener('click', () => {
|
|
560
|
+
const copy = cloneFlowTree(current);
|
|
561
|
+
copy.splice(rowIndex, 1);
|
|
562
|
+
onChange?.(copy);
|
|
563
|
+
});
|
|
564
|
+
line.appendChild(removeBtn);
|
|
565
|
+
root.appendChild(line);
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
const addBtn = dom('button', 'ft-prop-dashed-btn');
|
|
570
|
+
addBtn.type = 'button';
|
|
571
|
+
addBtn.append(iconSpan('ui.add', 'nova-icon nova-icon-xs'), dom('span', '', addLabel));
|
|
572
|
+
addBtn.addEventListener('click', () => {
|
|
573
|
+
const blank = Object.fromEntries(columns.map((col) => [col.key, col.defaultValue ?? '']));
|
|
574
|
+
onChange?.([...current, blank]);
|
|
575
|
+
});
|
|
576
|
+
root.appendChild(addBtn);
|
|
577
|
+
return root;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
export function createEmbeddedStepsEditor({ node, controller, i18n }) {
|
|
581
|
+
const t = (key, params) => i18n.t(key, params);
|
|
582
|
+
const steps = Array.isArray(node.config?.steps) ? node.config.steps : [];
|
|
583
|
+
const root = dom('div', 'ft-embedded-editor');
|
|
584
|
+
|
|
585
|
+
if (!steps.length) {
|
|
586
|
+
root.appendChild(dom('div', 'ft-prop-empty-box', t('flowTree.properties.embeddedSteps.empty')));
|
|
587
|
+
} else {
|
|
588
|
+
const list = dom('div', 'ft-embedded-list');
|
|
589
|
+
steps.forEach((step, index) => {
|
|
590
|
+
const row = dom('div', 'ft-embedded-row');
|
|
591
|
+
const info = dom('button', 'ft-embedded-select');
|
|
592
|
+
info.type = 'button';
|
|
593
|
+
info.append(
|
|
594
|
+
dom('span', 'ft-embedded-idx', String(index + 1)),
|
|
595
|
+
dom('strong', '', step.name || step.id),
|
|
596
|
+
dom('small', '', i18n.t(`flowTree.nodeTypes.${step.type}`)),
|
|
597
|
+
);
|
|
598
|
+
info.addEventListener('click', () => controller.commands.select({ kind: 'node', id: step.id }));
|
|
599
|
+
const del = dom('button', 'ft-icon-btn is-danger');
|
|
600
|
+
del.type = 'button';
|
|
601
|
+
del.appendChild(iconSpan('ui.delete', 'nova-icon nova-icon-xs'));
|
|
602
|
+
del.addEventListener('click', () => controller.commands.removeNode(step.id));
|
|
603
|
+
row.append(info, del);
|
|
604
|
+
list.appendChild(row);
|
|
605
|
+
});
|
|
606
|
+
root.appendChild(list);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
const actions = dom('div', 'ft-embedded-actions');
|
|
610
|
+
for (const item of [
|
|
611
|
+
{ type: 'approver', labelKey: 'flowTree.properties.embeddedSteps.addApprover' },
|
|
612
|
+
{ type: 'cc', labelKey: 'flowTree.properties.embeddedSteps.addCc' },
|
|
613
|
+
{ type: 'handler', labelKey: 'flowTree.properties.embeddedSteps.addHandler' },
|
|
614
|
+
{ type: 'trigger', labelKey: 'flowTree.properties.embeddedSteps.addTrigger' },
|
|
615
|
+
]) {
|
|
616
|
+
const btn = dom('button', 'ft-prop-mini-btn', t(item.labelKey));
|
|
617
|
+
btn.type = 'button';
|
|
618
|
+
btn.addEventListener('click', () => {
|
|
619
|
+
controller.commands.insertStep({ kind: 'embedded', subFlowId: node.id }, steps.length, item.type);
|
|
620
|
+
});
|
|
621
|
+
actions.appendChild(btn);
|
|
622
|
+
}
|
|
623
|
+
root.appendChild(actions);
|
|
624
|
+
return root;
|
|
625
|
+
}
|
|
@@ -356,13 +356,21 @@ function buildVisibleGraph(model, predicate, orientation = 'horizontal') {
|
|
|
356
356
|
return copy;
|
|
357
357
|
}
|
|
358
358
|
|
|
359
|
+
function isApprovalProjectionNode(node) {
|
|
360
|
+
const def = NODE_DEFINITIONS[node.type] || {};
|
|
361
|
+
if (['start', 'end'].includes(def.eventStage)) return true;
|
|
362
|
+
if (['userTask', 'callActivity'].includes(node.type)) return true;
|
|
363
|
+
if (node.type === 'serviceTask' && node.properties?.extensionAttributes?.['nova:nodeKind'] === 'cc') return true;
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
|
|
359
367
|
export function projectModel(model, projection = 'standard') {
|
|
360
368
|
const rootGraph = getScopeGraph(model, model.id);
|
|
361
369
|
if (projection === 'approval') {
|
|
362
|
-
return buildVisibleGraph(rootGraph,
|
|
370
|
+
return buildVisibleGraph(rootGraph, isApprovalProjectionNode, 'horizontal');
|
|
363
371
|
}
|
|
364
372
|
if (projection === 'compact') {
|
|
365
|
-
return buildVisibleGraph(rootGraph,
|
|
373
|
+
return buildVisibleGraph(rootGraph, isApprovalProjectionNode, 'vertical');
|
|
366
374
|
}
|
|
367
375
|
return cloneModel(rootGraph);
|
|
368
376
|
}
|