@bpmnkit/core 0.5.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bpmn/argument-guards.d.ts +21 -0
- package/dist/bpmn/argument-guards.js +90 -0
- package/dist/bpmn/compact.js +3 -0
- package/dist/bpmn/full-operations.js +4 -0
- package/dist/bpmn/operations.d.ts +3 -0
- package/dist/bpmn/operations.js +5 -0
- package/dist/form/form-builder.d.ts +27 -10
- package/dist/form/form-builder.js +114 -41
- package/dist/form/form-model.d.ts +16 -0
- package/dist/form/index.d.ts +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/types/stable-key.d.ts +20 -0
- package/dist/types/stable-key.js +51 -0
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { BpmnDefinitions } from "./bpmn-model.js";
|
|
2
|
+
import type { CompactDiagram } from "./compact.js";
|
|
3
|
+
/**
|
|
4
|
+
* Rejects anything that is not a {@link CompactDiagram} before it reaches code
|
|
5
|
+
* that assumes one.
|
|
6
|
+
*
|
|
7
|
+
* @param value - The argument as given.
|
|
8
|
+
* @param fn - The public function the argument was passed to, for the message.
|
|
9
|
+
* @throws {TypeError} When `value` cannot be walked as a compact diagram.
|
|
10
|
+
*/
|
|
11
|
+
export declare function assertCompactDiagram(value: unknown, fn: string): asserts value is CompactDiagram;
|
|
12
|
+
/**
|
|
13
|
+
* Rejects anything that is not a {@link BpmnDefinitions} before it reaches code
|
|
14
|
+
* that assumes one.
|
|
15
|
+
*
|
|
16
|
+
* @param value - The argument as given.
|
|
17
|
+
* @param fn - The public function the argument was passed to, for the message.
|
|
18
|
+
* @throws {TypeError} When `value` cannot be walked as a parsed model.
|
|
19
|
+
*/
|
|
20
|
+
export declare function assertBpmnDefinitions(value: unknown, fn: string): asserts value is BpmnDefinitions;
|
|
21
|
+
//# sourceMappingURL=argument-guards.d.ts.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime shape checks for the two document types the editing APIs take.
|
|
3
|
+
*
|
|
4
|
+
* Both are ordinary typed parameters, so a caller reaching for the neighbouring
|
|
5
|
+
* API — `Bpmn.parse()` takes raw XML, `compactify()` takes a parsed model — used
|
|
6
|
+
* to get an internal `TypeError` naming a private field, or, with an empty
|
|
7
|
+
* operation list, their own input handed straight back as if the edit had run.
|
|
8
|
+
* That second case is the dangerous one: it reads as a pipeline that ran and
|
|
9
|
+
* preserved everything.
|
|
10
|
+
*/
|
|
11
|
+
function isRecord(value) {
|
|
12
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
13
|
+
}
|
|
14
|
+
/** A compact process is walked through `elements` and `flows`. */
|
|
15
|
+
function isCompactProcess(value) {
|
|
16
|
+
return isRecord(value) && Array.isArray(value.elements) && Array.isArray(value.flows);
|
|
17
|
+
}
|
|
18
|
+
/** A full process is walked through `flowElements` and `sequenceFlows`. */
|
|
19
|
+
function isFullProcess(value) {
|
|
20
|
+
return isRecord(value) && Array.isArray(value.flowElements) && Array.isArray(value.sequenceFlows);
|
|
21
|
+
}
|
|
22
|
+
/** Names a non-object argument the way an error message wants to read. */
|
|
23
|
+
function describe(value) {
|
|
24
|
+
if (value === null)
|
|
25
|
+
return "null";
|
|
26
|
+
if (value === undefined)
|
|
27
|
+
return "undefined";
|
|
28
|
+
if (Array.isArray(value))
|
|
29
|
+
return "an array";
|
|
30
|
+
return `a ${typeof value}`;
|
|
31
|
+
}
|
|
32
|
+
/** Every process in a non-empty list has the other document's shape. */
|
|
33
|
+
function allProcessesAre(processes, shape) {
|
|
34
|
+
return processes.length > 0 && processes.every(shape);
|
|
35
|
+
}
|
|
36
|
+
function compactProblem(value) {
|
|
37
|
+
if (!isRecord(value)) {
|
|
38
|
+
const hint = typeof value === "string" ? " Pass compactify(Bpmn.parse(xml)) if you have raw XML." : "";
|
|
39
|
+
return `received ${describe(value)}.${hint}`;
|
|
40
|
+
}
|
|
41
|
+
if (!Array.isArray(value.processes))
|
|
42
|
+
return "received an object with no processes array.";
|
|
43
|
+
if (allProcessesAre(value.processes, isFullProcess))
|
|
44
|
+
return "received a BpmnDefinitions. Pass compactify(defs).";
|
|
45
|
+
const bad = value.processes.findIndex((process) => !isCompactProcess(process));
|
|
46
|
+
if (bad >= 0)
|
|
47
|
+
return `received one whose processes[${bad}] has no elements and flows arrays.`;
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
function definitionsProblem(value) {
|
|
51
|
+
if (!isRecord(value)) {
|
|
52
|
+
const hint = typeof value === "string" ? " Pass Bpmn.parse(xml) if you have raw XML." : "";
|
|
53
|
+
return `received ${describe(value)}.${hint}`;
|
|
54
|
+
}
|
|
55
|
+
if (!Array.isArray(value.processes))
|
|
56
|
+
return "received an object with no processes array.";
|
|
57
|
+
if (allProcessesAre(value.processes, isCompactProcess))
|
|
58
|
+
return "received a CompactDiagram. Pass the parsed model, not the compact projection.";
|
|
59
|
+
const bad = value.processes.findIndex((process) => !isFullProcess(process));
|
|
60
|
+
if (bad >= 0)
|
|
61
|
+
return `received one whose processes[${bad}] has no flowElements and sequenceFlows arrays.`;
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Rejects anything that is not a {@link CompactDiagram} before it reaches code
|
|
66
|
+
* that assumes one.
|
|
67
|
+
*
|
|
68
|
+
* @param value - The argument as given.
|
|
69
|
+
* @param fn - The public function the argument was passed to, for the message.
|
|
70
|
+
* @throws {TypeError} When `value` cannot be walked as a compact diagram.
|
|
71
|
+
*/
|
|
72
|
+
export function assertCompactDiagram(value, fn) {
|
|
73
|
+
const problem = compactProblem(value);
|
|
74
|
+
if (problem)
|
|
75
|
+
throw new TypeError(`${fn} expects a CompactDiagram, ${problem}`);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Rejects anything that is not a {@link BpmnDefinitions} before it reaches code
|
|
79
|
+
* that assumes one.
|
|
80
|
+
*
|
|
81
|
+
* @param value - The argument as given.
|
|
82
|
+
* @param fn - The public function the argument was passed to, for the message.
|
|
83
|
+
* @throws {TypeError} When `value` cannot be walked as a parsed model.
|
|
84
|
+
*/
|
|
85
|
+
export function assertBpmnDefinitions(value, fn) {
|
|
86
|
+
const problem = definitionsProblem(value);
|
|
87
|
+
if (problem)
|
|
88
|
+
throw new TypeError(`${fn} expects a BpmnDefinitions, ${problem}`);
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=argument-guards.js.map
|
package/dist/bpmn/compact.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { layoutProcess } from "../layout/index.js";
|
|
2
|
+
import { assertBpmnDefinitions, assertCompactDiagram } from "./argument-guards.js";
|
|
2
3
|
// ── Compactify ───────────────────────────────────────────────────────────────
|
|
3
4
|
function findAttr(ext, name, attr) {
|
|
4
5
|
return ext.find((e) => e.name === name)?.attributes[attr];
|
|
@@ -105,6 +106,7 @@ function compactifyElement(el) {
|
|
|
105
106
|
* ```
|
|
106
107
|
*/
|
|
107
108
|
export function compactify(defs) {
|
|
109
|
+
assertBpmnDefinitions(defs, "compactify");
|
|
108
110
|
return {
|
|
109
111
|
id: defs.id,
|
|
110
112
|
processes: defs.processes.map((process) => ({
|
|
@@ -409,6 +411,7 @@ function expandProcess(compact) {
|
|
|
409
411
|
* ```
|
|
410
412
|
*/
|
|
411
413
|
export function expand(compact) {
|
|
414
|
+
assertCompactDiagram(compact, "expand");
|
|
412
415
|
const processes = [];
|
|
413
416
|
const diagrams = [];
|
|
414
417
|
for (const cp of compact.processes) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assertBpmnDefinitions, assertCompactDiagram } from "./argument-guards.js";
|
|
1
2
|
import { buildFlowElement, makeEventDef, } from "./compact.js";
|
|
2
3
|
import { bpmnElementName, ensureZeebeExtension, isZeebePlacementAllowed, } from "./zeebe-extensions.js";
|
|
3
4
|
/** Thrown by {@link applyBpmnOperations} in strict mode. */
|
|
@@ -231,6 +232,7 @@ function patchElement(element, patch) {
|
|
|
231
232
|
* ```
|
|
232
233
|
*/
|
|
233
234
|
export function applyBpmnOperations(definitions, operations, options = {}) {
|
|
235
|
+
assertBpmnDefinitions(definitions, "applyBpmnOperations");
|
|
234
236
|
const draft = structuredClone(definitions);
|
|
235
237
|
const problems = [];
|
|
236
238
|
let applied = 0;
|
|
@@ -385,6 +387,8 @@ function recomputeRefs(container) {
|
|
|
385
387
|
* @returns The updated model, plus what applied and what did not.
|
|
386
388
|
*/
|
|
387
389
|
export function reconcileCompact(definitions, compact, options = {}) {
|
|
390
|
+
assertBpmnDefinitions(definitions, "reconcileCompact");
|
|
391
|
+
assertCompactDiagram(compact, "reconcileCompact");
|
|
388
392
|
const draft = structuredClone(definitions);
|
|
389
393
|
for (const compactProcess of compact.processes) {
|
|
390
394
|
if (!draft.processes.some((process) => process.id === compactProcess.id)) {
|
|
@@ -77,6 +77,9 @@ export type BpmnOperation =
|
|
|
77
77
|
* ])
|
|
78
78
|
* const xml = Bpmn.export(expand(updated))
|
|
79
79
|
* ```
|
|
80
|
+
*
|
|
81
|
+
* @throws {TypeError} When `diagram` is not a CompactDiagram. Raw XML is the
|
|
82
|
+
* easy mistake — `compactify(Bpmn.parse(xml))` is the way in.
|
|
80
83
|
*/
|
|
81
84
|
export declare function applyOperations(diagram: CompactDiagram, ops: BpmnOperation[]): CompactDiagram;
|
|
82
85
|
//# sourceMappingURL=operations.d.ts.map
|
package/dist/bpmn/operations.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assertCompactDiagram } from "./argument-guards.js";
|
|
1
2
|
function findElementIn(container, id) {
|
|
2
3
|
for (let i = 0; i < container.elements.length; i++) {
|
|
3
4
|
const el = container.elements[i];
|
|
@@ -141,8 +142,12 @@ function applyOne(diagram, op) {
|
|
|
141
142
|
* ])
|
|
142
143
|
* const xml = Bpmn.export(expand(updated))
|
|
143
144
|
* ```
|
|
145
|
+
*
|
|
146
|
+
* @throws {TypeError} When `diagram` is not a CompactDiagram. Raw XML is the
|
|
147
|
+
* easy mistake — `compactify(Bpmn.parse(xml))` is the way in.
|
|
144
148
|
*/
|
|
145
149
|
export function applyOperations(diagram, ops) {
|
|
150
|
+
assertCompactDiagram(diagram, "applyOperations");
|
|
146
151
|
const result = structuredClone(diagram);
|
|
147
152
|
for (const op of ops) {
|
|
148
153
|
applyOne(result, op);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FormComponent, FormDefinition,
|
|
1
|
+
import type { FormComponent, FormDefinition, FormLayoutInput, FormValidation, FormValueOption } from "./form-model.js";
|
|
2
2
|
/** Builder for constructing Camunda Forms programmatically. */
|
|
3
3
|
export declare class FormBuilder {
|
|
4
4
|
private _id;
|
|
@@ -9,8 +9,17 @@ export declare class FormBuilder {
|
|
|
9
9
|
private _schemaVersion?;
|
|
10
10
|
private _generated?;
|
|
11
11
|
private readonly _components;
|
|
12
|
+
private _names;
|
|
12
13
|
constructor(id?: string);
|
|
13
|
-
/**
|
|
14
|
+
/**
|
|
15
|
+
* Sets the form ID.
|
|
16
|
+
*
|
|
17
|
+
* Set it before adding components. The form id is what scopes their generated
|
|
18
|
+
* ids and rows — so that one field key means different ids in two different
|
|
19
|
+
* forms — and components added earlier keep the names they were given under
|
|
20
|
+
* the previous id. Output stays deterministic either way; it just is not the
|
|
21
|
+
* same output as passing the id to the constructor.
|
|
22
|
+
*/
|
|
14
23
|
id(id: string): this;
|
|
15
24
|
/** Sets the execution platform. */
|
|
16
25
|
executionPlatform(platform: string): this;
|
|
@@ -26,7 +35,7 @@ export declare class FormBuilder {
|
|
|
26
35
|
text(text: string, options?: {
|
|
27
36
|
id?: string;
|
|
28
37
|
label?: string;
|
|
29
|
-
layout?:
|
|
38
|
+
layout?: FormLayoutInput;
|
|
30
39
|
}): this;
|
|
31
40
|
/** Adds a text field component. */
|
|
32
41
|
textfield(label: string, key: string, options?: TextFieldOptions): this;
|
|
@@ -51,11 +60,19 @@ export declare class GroupBuilder {
|
|
|
51
60
|
readonly _id: string;
|
|
52
61
|
/** @internal */
|
|
53
62
|
readonly _components: FormComponent[];
|
|
63
|
+
private readonly _names;
|
|
64
|
+
/**
|
|
65
|
+
* @param id - The group component's id, and the scope its children's generated
|
|
66
|
+
* ids and rows hang off. `FormBuilder.group()` passes the id it resolved for
|
|
67
|
+
* the group, which is itself derived from the form id, so a nested tree is
|
|
68
|
+
* deterministic all the way down. A group built standalone without an id
|
|
69
|
+
* gets a random one, and its children inherit that instability.
|
|
70
|
+
*/
|
|
54
71
|
constructor(id?: string);
|
|
55
72
|
text(text: string, options?: {
|
|
56
73
|
id?: string;
|
|
57
74
|
label?: string;
|
|
58
|
-
layout?:
|
|
75
|
+
layout?: FormLayoutInput;
|
|
59
76
|
}): this;
|
|
60
77
|
textfield(label: string, key: string, options?: TextFieldOptions): this;
|
|
61
78
|
textarea(label: string, key: string, options?: TextFieldOptions): this;
|
|
@@ -70,7 +87,7 @@ export interface TextFieldOptions {
|
|
|
70
87
|
id?: string;
|
|
71
88
|
validate?: FormValidation;
|
|
72
89
|
defaultValue?: string;
|
|
73
|
-
layout?:
|
|
90
|
+
layout?: FormLayoutInput;
|
|
74
91
|
}
|
|
75
92
|
/** Options for select components. */
|
|
76
93
|
export interface SelectOptions {
|
|
@@ -80,32 +97,32 @@ export interface SelectOptions {
|
|
|
80
97
|
validate?: FormValidation;
|
|
81
98
|
searchable?: boolean;
|
|
82
99
|
defaultValue?: string;
|
|
83
|
-
layout?:
|
|
100
|
+
layout?: FormLayoutInput;
|
|
84
101
|
}
|
|
85
102
|
/** Options for radio components. */
|
|
86
103
|
export interface RadioOptions {
|
|
87
104
|
id?: string;
|
|
88
105
|
validate?: FormValidation;
|
|
89
106
|
defaultValue?: string;
|
|
90
|
-
layout?:
|
|
107
|
+
layout?: FormLayoutInput;
|
|
91
108
|
}
|
|
92
109
|
/** Options for checkbox components. */
|
|
93
110
|
export interface CheckboxOptions {
|
|
94
111
|
id?: string;
|
|
95
112
|
validate?: FormValidation;
|
|
96
113
|
defaultValue?: boolean;
|
|
97
|
-
layout?:
|
|
114
|
+
layout?: FormLayoutInput;
|
|
98
115
|
}
|
|
99
116
|
/** Options for checklist components. */
|
|
100
117
|
export interface ChecklistOptions {
|
|
101
118
|
id?: string;
|
|
102
119
|
validate?: FormValidation;
|
|
103
|
-
layout?:
|
|
120
|
+
layout?: FormLayoutInput;
|
|
104
121
|
}
|
|
105
122
|
/** Options for group components. */
|
|
106
123
|
export interface GroupOptions {
|
|
107
124
|
id?: string;
|
|
108
125
|
showOutline?: boolean;
|
|
109
|
-
layout?:
|
|
126
|
+
layout?: FormLayoutInput;
|
|
110
127
|
}
|
|
111
128
|
//# sourceMappingURL=form-builder.d.ts.map
|
|
@@ -1,14 +1,51 @@
|
|
|
1
1
|
import { generateId } from "../types/id-generator.js";
|
|
2
|
+
import { compositeKey, stableToken } from "../types/stable-key.js";
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Mints the id and layout row for the components of one scope — a form, or a
|
|
5
|
+
* group inside it.
|
|
6
|
+
*
|
|
7
|
+
* Every generated component carries a layout because Camunda Modeler and the
|
|
8
|
+
* form-js importer read a missing `layout` as a legacy schema and backfill a
|
|
9
|
+
* row/columns pair on open, showing a spurious diff on a form this builder just
|
|
10
|
+
* produced. Both values are derived from the component's own identity — its
|
|
11
|
+
* field key, or its text for a static block — rather than from its position or
|
|
12
|
+
* from a random draw, so rebuilding an unchanged form is byte-identical and
|
|
13
|
+
* reordering two fields moves nothing but their order. The row lives in its own
|
|
14
|
+
* `"row"` namespace so it never equals the id derived from the same identity.
|
|
15
|
+
*
|
|
16
|
+
* `occurrences` covers the one case identity cannot: two components of a type
|
|
17
|
+
* that are genuinely indistinguishable. Nothing intrinsic separates them, so
|
|
18
|
+
* they are numbered in the order they were added.
|
|
6
19
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
20
|
+
class ScopeNames {
|
|
21
|
+
scope;
|
|
22
|
+
occurrences = new Map();
|
|
23
|
+
constructor(scope) {
|
|
24
|
+
this.scope = scope;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @param type - The component's `type` discriminator.
|
|
28
|
+
* @param identity - What the component is known by: its field key, or its
|
|
29
|
+
* text or label when it has no key.
|
|
30
|
+
*/
|
|
31
|
+
resolve(type, identity, options) {
|
|
32
|
+
const segments = [this.scope, type, identity];
|
|
33
|
+
const key = compositeKey(segments);
|
|
34
|
+
const occurrence = (this.occurrences.get(key) ?? 0) + 1;
|
|
35
|
+
this.occurrences.set(key, occurrence);
|
|
36
|
+
if (occurrence > 1)
|
|
37
|
+
segments.push(`#${occurrence}`);
|
|
38
|
+
return {
|
|
39
|
+
id: options?.id ?? stableToken("Field", segments),
|
|
40
|
+
layout: {
|
|
41
|
+
// `??` is the whole null asymmetry documented on FormLayoutInput: a
|
|
42
|
+
// null row falls through to a generated one, a null columns lands on
|
|
43
|
+
// null and is kept.
|
|
44
|
+
row: options?.layout?.row ?? stableToken("Row", [...segments, "row"]),
|
|
45
|
+
columns: options?.layout?.columns ?? null,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
12
49
|
}
|
|
13
50
|
/** Builder for constructing Camunda Forms programmatically. */
|
|
14
51
|
export class FormBuilder {
|
|
@@ -20,12 +57,23 @@ export class FormBuilder {
|
|
|
20
57
|
_schemaVersion;
|
|
21
58
|
_generated;
|
|
22
59
|
_components = [];
|
|
60
|
+
_names;
|
|
23
61
|
constructor(id) {
|
|
24
62
|
this._id = id ?? generateId("Form");
|
|
63
|
+
this._names = new ScopeNames(this._id);
|
|
25
64
|
}
|
|
26
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* Sets the form ID.
|
|
67
|
+
*
|
|
68
|
+
* Set it before adding components. The form id is what scopes their generated
|
|
69
|
+
* ids and rows — so that one field key means different ids in two different
|
|
70
|
+
* forms — and components added earlier keep the names they were given under
|
|
71
|
+
* the previous id. Output stays deterministic either way; it just is not the
|
|
72
|
+
* same output as passing the id to the constructor.
|
|
73
|
+
*/
|
|
27
74
|
id(id) {
|
|
28
75
|
this._id = id;
|
|
76
|
+
this._names = new ScopeNames(id);
|
|
29
77
|
return this;
|
|
30
78
|
}
|
|
31
79
|
/** Sets the execution platform. */
|
|
@@ -55,22 +103,24 @@ export class FormBuilder {
|
|
|
55
103
|
}
|
|
56
104
|
/** Adds a static text component. */
|
|
57
105
|
text(text, options) {
|
|
106
|
+
const names = this._names.resolve("text", text, options);
|
|
58
107
|
const component = {
|
|
59
108
|
type: "text",
|
|
60
|
-
id:
|
|
109
|
+
id: names.id,
|
|
61
110
|
text,
|
|
62
111
|
};
|
|
63
112
|
if (options?.label !== undefined)
|
|
64
113
|
component.label = options.label;
|
|
65
|
-
component.layout =
|
|
114
|
+
component.layout = names.layout;
|
|
66
115
|
this._components.push(component);
|
|
67
116
|
return this;
|
|
68
117
|
}
|
|
69
118
|
/** Adds a text field component. */
|
|
70
119
|
textfield(label, key, options) {
|
|
120
|
+
const names = this._names.resolve("textfield", key, options);
|
|
71
121
|
const component = {
|
|
72
122
|
type: "textfield",
|
|
73
|
-
id:
|
|
123
|
+
id: names.id,
|
|
74
124
|
label,
|
|
75
125
|
key,
|
|
76
126
|
};
|
|
@@ -78,15 +128,16 @@ export class FormBuilder {
|
|
|
78
128
|
component.validate = options.validate;
|
|
79
129
|
if (options?.defaultValue !== undefined)
|
|
80
130
|
component.defaultValue = options.defaultValue;
|
|
81
|
-
component.layout =
|
|
131
|
+
component.layout = names.layout;
|
|
82
132
|
this._components.push(component);
|
|
83
133
|
return this;
|
|
84
134
|
}
|
|
85
135
|
/** Adds a textarea component. */
|
|
86
136
|
textarea(label, key, options) {
|
|
137
|
+
const names = this._names.resolve("textarea", key, options);
|
|
87
138
|
const component = {
|
|
88
139
|
type: "textarea",
|
|
89
|
-
id:
|
|
140
|
+
id: names.id,
|
|
90
141
|
label,
|
|
91
142
|
key,
|
|
92
143
|
};
|
|
@@ -94,15 +145,16 @@ export class FormBuilder {
|
|
|
94
145
|
component.validate = options.validate;
|
|
95
146
|
if (options?.defaultValue !== undefined)
|
|
96
147
|
component.defaultValue = options.defaultValue;
|
|
97
|
-
component.layout =
|
|
148
|
+
component.layout = names.layout;
|
|
98
149
|
this._components.push(component);
|
|
99
150
|
return this;
|
|
100
151
|
}
|
|
101
152
|
/** Adds a select dropdown component. */
|
|
102
153
|
select(label, key, options) {
|
|
154
|
+
const names = this._names.resolve("select", key, options);
|
|
103
155
|
const component = {
|
|
104
156
|
type: "select",
|
|
105
|
-
id:
|
|
157
|
+
id: names.id,
|
|
106
158
|
label,
|
|
107
159
|
key,
|
|
108
160
|
};
|
|
@@ -116,15 +168,16 @@ export class FormBuilder {
|
|
|
116
168
|
component.searchable = options.searchable;
|
|
117
169
|
if (options?.defaultValue !== undefined)
|
|
118
170
|
component.defaultValue = options.defaultValue;
|
|
119
|
-
component.layout =
|
|
171
|
+
component.layout = names.layout;
|
|
120
172
|
this._components.push(component);
|
|
121
173
|
return this;
|
|
122
174
|
}
|
|
123
175
|
/** Adds a radio button group component. */
|
|
124
176
|
radio(label, key, values, options) {
|
|
177
|
+
const names = this._names.resolve("radio", key, options);
|
|
125
178
|
const component = {
|
|
126
179
|
type: "radio",
|
|
127
|
-
id:
|
|
180
|
+
id: names.id,
|
|
128
181
|
label,
|
|
129
182
|
key,
|
|
130
183
|
values,
|
|
@@ -133,15 +186,16 @@ export class FormBuilder {
|
|
|
133
186
|
component.validate = options.validate;
|
|
134
187
|
if (options?.defaultValue !== undefined)
|
|
135
188
|
component.defaultValue = options.defaultValue;
|
|
136
|
-
component.layout =
|
|
189
|
+
component.layout = names.layout;
|
|
137
190
|
this._components.push(component);
|
|
138
191
|
return this;
|
|
139
192
|
}
|
|
140
193
|
/** Adds a checkbox component. */
|
|
141
194
|
checkbox(label, key, options) {
|
|
195
|
+
const names = this._names.resolve("checkbox", key, options);
|
|
142
196
|
const component = {
|
|
143
197
|
type: "checkbox",
|
|
144
|
-
id:
|
|
198
|
+
id: names.id,
|
|
145
199
|
label,
|
|
146
200
|
key,
|
|
147
201
|
};
|
|
@@ -149,28 +203,30 @@ export class FormBuilder {
|
|
|
149
203
|
component.validate = options.validate;
|
|
150
204
|
if (options?.defaultValue !== undefined)
|
|
151
205
|
component.defaultValue = options.defaultValue;
|
|
152
|
-
component.layout =
|
|
206
|
+
component.layout = names.layout;
|
|
153
207
|
this._components.push(component);
|
|
154
208
|
return this;
|
|
155
209
|
}
|
|
156
210
|
/** Adds a checklist component. */
|
|
157
211
|
checklist(label, key, values, options) {
|
|
212
|
+
const names = this._names.resolve("checklist", key, options);
|
|
158
213
|
const component = {
|
|
159
214
|
type: "checklist",
|
|
160
|
-
id:
|
|
215
|
+
id: names.id,
|
|
161
216
|
label,
|
|
162
217
|
key,
|
|
163
218
|
values,
|
|
164
219
|
};
|
|
165
220
|
if (options?.validate !== undefined)
|
|
166
221
|
component.validate = options.validate;
|
|
167
|
-
component.layout =
|
|
222
|
+
component.layout = names.layout;
|
|
168
223
|
this._components.push(component);
|
|
169
224
|
return this;
|
|
170
225
|
}
|
|
171
226
|
/** Adds a group component with nested children built via a callback. */
|
|
172
227
|
group(label, builder, options) {
|
|
173
|
-
const
|
|
228
|
+
const names = this._names.resolve("group", label, options);
|
|
229
|
+
const groupBuilder = new GroupBuilder(names.id);
|
|
174
230
|
builder(groupBuilder);
|
|
175
231
|
const component = {
|
|
176
232
|
type: "group",
|
|
@@ -180,7 +236,7 @@ export class FormBuilder {
|
|
|
180
236
|
};
|
|
181
237
|
if (options?.showOutline !== undefined)
|
|
182
238
|
component.showOutline = options.showOutline;
|
|
183
|
-
component.layout =
|
|
239
|
+
component.layout = names.layout;
|
|
184
240
|
this._components.push(component);
|
|
185
241
|
return this;
|
|
186
242
|
}
|
|
@@ -212,25 +268,36 @@ export class GroupBuilder {
|
|
|
212
268
|
_id;
|
|
213
269
|
/** @internal */
|
|
214
270
|
_components = [];
|
|
271
|
+
_names;
|
|
272
|
+
/**
|
|
273
|
+
* @param id - The group component's id, and the scope its children's generated
|
|
274
|
+
* ids and rows hang off. `FormBuilder.group()` passes the id it resolved for
|
|
275
|
+
* the group, which is itself derived from the form id, so a nested tree is
|
|
276
|
+
* deterministic all the way down. A group built standalone without an id
|
|
277
|
+
* gets a random one, and its children inherit that instability.
|
|
278
|
+
*/
|
|
215
279
|
constructor(id) {
|
|
216
280
|
this._id = id ?? generateId("Field");
|
|
281
|
+
this._names = new ScopeNames(this._id);
|
|
217
282
|
}
|
|
218
283
|
text(text, options) {
|
|
284
|
+
const names = this._names.resolve("text", text, options);
|
|
219
285
|
const component = {
|
|
220
286
|
type: "text",
|
|
221
|
-
id:
|
|
287
|
+
id: names.id,
|
|
222
288
|
text,
|
|
223
289
|
};
|
|
224
290
|
if (options?.label !== undefined)
|
|
225
291
|
component.label = options.label;
|
|
226
|
-
component.layout =
|
|
292
|
+
component.layout = names.layout;
|
|
227
293
|
this._components.push(component);
|
|
228
294
|
return this;
|
|
229
295
|
}
|
|
230
296
|
textfield(label, key, options) {
|
|
297
|
+
const names = this._names.resolve("textfield", key, options);
|
|
231
298
|
const component = {
|
|
232
299
|
type: "textfield",
|
|
233
|
-
id:
|
|
300
|
+
id: names.id,
|
|
234
301
|
label,
|
|
235
302
|
key,
|
|
236
303
|
};
|
|
@@ -238,14 +305,15 @@ export class GroupBuilder {
|
|
|
238
305
|
component.validate = options.validate;
|
|
239
306
|
if (options?.defaultValue !== undefined)
|
|
240
307
|
component.defaultValue = options.defaultValue;
|
|
241
|
-
component.layout =
|
|
308
|
+
component.layout = names.layout;
|
|
242
309
|
this._components.push(component);
|
|
243
310
|
return this;
|
|
244
311
|
}
|
|
245
312
|
textarea(label, key, options) {
|
|
313
|
+
const names = this._names.resolve("textarea", key, options);
|
|
246
314
|
const component = {
|
|
247
315
|
type: "textarea",
|
|
248
|
-
id:
|
|
316
|
+
id: names.id,
|
|
249
317
|
label,
|
|
250
318
|
key,
|
|
251
319
|
};
|
|
@@ -253,14 +321,15 @@ export class GroupBuilder {
|
|
|
253
321
|
component.validate = options.validate;
|
|
254
322
|
if (options?.defaultValue !== undefined)
|
|
255
323
|
component.defaultValue = options.defaultValue;
|
|
256
|
-
component.layout =
|
|
324
|
+
component.layout = names.layout;
|
|
257
325
|
this._components.push(component);
|
|
258
326
|
return this;
|
|
259
327
|
}
|
|
260
328
|
select(label, key, options) {
|
|
329
|
+
const names = this._names.resolve("select", key, options);
|
|
261
330
|
const component = {
|
|
262
331
|
type: "select",
|
|
263
|
-
id:
|
|
332
|
+
id: names.id,
|
|
264
333
|
label,
|
|
265
334
|
key,
|
|
266
335
|
};
|
|
@@ -274,14 +343,15 @@ export class GroupBuilder {
|
|
|
274
343
|
component.searchable = options.searchable;
|
|
275
344
|
if (options?.defaultValue !== undefined)
|
|
276
345
|
component.defaultValue = options.defaultValue;
|
|
277
|
-
component.layout =
|
|
346
|
+
component.layout = names.layout;
|
|
278
347
|
this._components.push(component);
|
|
279
348
|
return this;
|
|
280
349
|
}
|
|
281
350
|
radio(label, key, values, options) {
|
|
351
|
+
const names = this._names.resolve("radio", key, options);
|
|
282
352
|
const component = {
|
|
283
353
|
type: "radio",
|
|
284
|
-
id:
|
|
354
|
+
id: names.id,
|
|
285
355
|
label,
|
|
286
356
|
key,
|
|
287
357
|
values,
|
|
@@ -290,14 +360,15 @@ export class GroupBuilder {
|
|
|
290
360
|
component.validate = options.validate;
|
|
291
361
|
if (options?.defaultValue !== undefined)
|
|
292
362
|
component.defaultValue = options.defaultValue;
|
|
293
|
-
component.layout =
|
|
363
|
+
component.layout = names.layout;
|
|
294
364
|
this._components.push(component);
|
|
295
365
|
return this;
|
|
296
366
|
}
|
|
297
367
|
checkbox(label, key, options) {
|
|
368
|
+
const names = this._names.resolve("checkbox", key, options);
|
|
298
369
|
const component = {
|
|
299
370
|
type: "checkbox",
|
|
300
|
-
id:
|
|
371
|
+
id: names.id,
|
|
301
372
|
label,
|
|
302
373
|
key,
|
|
303
374
|
};
|
|
@@ -305,26 +376,28 @@ export class GroupBuilder {
|
|
|
305
376
|
component.validate = options.validate;
|
|
306
377
|
if (options?.defaultValue !== undefined)
|
|
307
378
|
component.defaultValue = options.defaultValue;
|
|
308
|
-
component.layout =
|
|
379
|
+
component.layout = names.layout;
|
|
309
380
|
this._components.push(component);
|
|
310
381
|
return this;
|
|
311
382
|
}
|
|
312
383
|
checklist(label, key, values, options) {
|
|
384
|
+
const names = this._names.resolve("checklist", key, options);
|
|
313
385
|
const component = {
|
|
314
386
|
type: "checklist",
|
|
315
|
-
id:
|
|
387
|
+
id: names.id,
|
|
316
388
|
label,
|
|
317
389
|
key,
|
|
318
390
|
values,
|
|
319
391
|
};
|
|
320
392
|
if (options?.validate !== undefined)
|
|
321
393
|
component.validate = options.validate;
|
|
322
|
-
component.layout =
|
|
394
|
+
component.layout = names.layout;
|
|
323
395
|
this._components.push(component);
|
|
324
396
|
return this;
|
|
325
397
|
}
|
|
326
398
|
group(label, builder, options) {
|
|
327
|
-
const
|
|
399
|
+
const names = this._names.resolve("group", label, options);
|
|
400
|
+
const groupBuilder = new GroupBuilder(names.id);
|
|
328
401
|
builder(groupBuilder);
|
|
329
402
|
const component = {
|
|
330
403
|
type: "group",
|
|
@@ -334,7 +407,7 @@ export class GroupBuilder {
|
|
|
334
407
|
};
|
|
335
408
|
if (options?.showOutline !== undefined)
|
|
336
409
|
component.showOutline = options.showOutline;
|
|
337
|
-
component.layout =
|
|
410
|
+
component.layout = names.layout;
|
|
338
411
|
this._components.push(component);
|
|
339
412
|
return this;
|
|
340
413
|
}
|
|
@@ -3,6 +3,22 @@ export interface FormLayout {
|
|
|
3
3
|
row?: string;
|
|
4
4
|
columns?: number | null;
|
|
5
5
|
}
|
|
6
|
+
/**
|
|
7
|
+
* A layout as a caller hands it to the builder. Both fields accept `null`, and
|
|
8
|
+
* the two mean opposite things — deliberately, and worth reading twice, because
|
|
9
|
+
* they are siblings in one object and easy to treat alike by mistake:
|
|
10
|
+
*
|
|
11
|
+
* - `row: null` is **not set**. A generated row is filled in. Renderers collapse
|
|
12
|
+
* every `row: null` field into one shared row, which is essentially never what
|
|
13
|
+
* a caller who declined to name a row was asking for, so `null` is not trusted
|
|
14
|
+
* here as an intentional value.
|
|
15
|
+
* - `columns: null` **is** intentional — the field spans its own row, which is
|
|
16
|
+
* the Camunda default — and is preserved as given.
|
|
17
|
+
*/
|
|
18
|
+
export interface FormLayoutInput {
|
|
19
|
+
row?: string | null;
|
|
20
|
+
columns?: number | null;
|
|
21
|
+
}
|
|
6
22
|
/** Validation constraints for a form field. */
|
|
7
23
|
export interface FormValidation {
|
|
8
24
|
required?: boolean;
|
package/dist/form/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type { FormComponent, FormButtonComponent, FormCheckboxComponent, FormChecklistComponent, FormDatetimeComponent, FormDefinition, FormDocumentPreviewComponent, FormDynamicListComponent, FormExporter, FormExpressionComponent, FormFilepickerComponent, FormGroupComponent, FormHtmlComponent, FormIframeComponent, FormImageComponent, FormLayout, FormNumberComponent, FormRadioComponent, FormSelectComponent, FormSeparatorComponent, FormSpacerComponent, FormTableComponent, FormTaglistComponent, FormTextAreaComponent, FormTextComponent, FormTextFieldComponent, FormUnknownComponent, FormValidation, FormValueOption, } from "./form-model.js";
|
|
1
|
+
export type { FormComponent, FormButtonComponent, FormCheckboxComponent, FormChecklistComponent, FormDatetimeComponent, FormDefinition, FormDocumentPreviewComponent, FormDynamicListComponent, FormExporter, FormExpressionComponent, FormFilepickerComponent, FormGroupComponent, FormHtmlComponent, FormIframeComponent, FormImageComponent, FormLayout, FormLayoutInput, FormNumberComponent, FormRadioComponent, FormSelectComponent, FormSeparatorComponent, FormSpacerComponent, FormTableComponent, FormTaglistComponent, FormTextAreaComponent, FormTextComponent, FormTextFieldComponent, FormUnknownComponent, FormValidation, FormValueOption, } from "./form-model.js";
|
|
2
2
|
export { parseForm } from "./form-parser.js";
|
|
3
3
|
export { exportForm } from "./form-serializer.js";
|
|
4
4
|
export { FormBuilder, GroupBuilder } from "./form-builder.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type { PreservingWriteResult } from "./bpmn/preserving-writer.js";
|
|
|
14
14
|
export { exportDmnPreserving, preserveDmnFormatting } from "./dmn/preserving-writer.js";
|
|
15
15
|
export type { BpmnDiffCategory, BpmnDiffPlaneSummary, BpmnDiffResult, } from "./bpmn/diagram-diff.js";
|
|
16
16
|
export { sha256Hex } from "./bpmn/sha256.js";
|
|
17
|
+
export { compositeKey, stableToken } from "./types/stable-key.js";
|
|
17
18
|
export { checkDiCompleteness } from "./bpmn/di-check.js";
|
|
18
19
|
export type { DiCompleteness } from "./bpmn/di-check.js";
|
|
19
20
|
export { planeForElement, listPlaneElementIds } from "./bpmn/di-planes.js";
|
|
@@ -32,7 +33,7 @@ export { Form, compactifyForm, expandForm } from "./form/index.js";
|
|
|
32
33
|
export type { CompactForm, CompactFormField } from "./form/index.js";
|
|
33
34
|
export { FormBuilder, GroupBuilder } from "./form/form-builder.js";
|
|
34
35
|
export type { TextFieldOptions, SelectOptions, RadioOptions, CheckboxOptions, ChecklistOptions, GroupOptions, } from "./form/form-builder.js";
|
|
35
|
-
export type { FormComponent, FormCheckboxComponent, FormChecklistComponent, FormDefinition, FormExporter, FormGroupComponent, FormLayout, FormRadioComponent, FormSelectComponent, FormTextAreaComponent, FormTextComponent, FormTextFieldComponent, FormValidation, FormValueOption, FormNumberComponent, FormDatetimeComponent, FormButtonComponent, FormTaglistComponent, FormTableComponent, FormImageComponent, FormDynamicListComponent, FormIframeComponent, FormSeparatorComponent, FormSpacerComponent, FormDocumentPreviewComponent, FormHtmlComponent, FormExpressionComponent, FormFilepickerComponent, FormUnknownComponent, } from "./form/form-model.js";
|
|
36
|
+
export type { FormComponent, FormCheckboxComponent, FormChecklistComponent, FormDefinition, FormExporter, FormGroupComponent, FormLayout, FormLayoutInput, FormRadioComponent, FormSelectComponent, FormTextAreaComponent, FormTextComponent, FormTextFieldComponent, FormValidation, FormValueOption, FormNumberComponent, FormDatetimeComponent, FormButtonComponent, FormTaglistComponent, FormTableComponent, FormImageComponent, FormDynamicListComponent, FormIframeComponent, FormSeparatorComponent, FormSpacerComponent, FormDocumentPreviewComponent, FormHtmlComponent, FormExpressionComponent, FormFilepickerComponent, FormUnknownComponent, } from "./form/form-model.js";
|
|
36
37
|
export type { DecisionTableBuilder, InputOptions, OutputOptions, RuleOptions, } from "./dmn/dmn-builder.js";
|
|
37
38
|
export type { DmnDefinitions, DmnDecision, DmnDecisionTable, DmnInput, DmnOutput, DmnRule, DmnInputEntry, DmnOutputEntry, DmnDiagram, DmnDiagramShape, DmnDiagramEdge, DmnWaypoint, DmnTypeRef, DmnAggregation, HitPolicy, DmnInformationRequirement, DmnKnowledgeRequirement, DmnAuthorityRequirement, DmnInputData, DmnKnowledgeSource, DmnBusinessKnowledgeModel, DmnTextAnnotation, DmnAssociation, } from "./dmn/dmn-model.js";
|
|
38
39
|
export type { XmlElement } from "./types/xml-element.js";
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export { diffDiagram } from "./bpmn/diagram-diff.js";
|
|
|
9
9
|
export { exportPreserving, exportPreservingResult, preserveBpmnFormatting, } from "./bpmn/preserving-writer.js";
|
|
10
10
|
export { exportDmnPreserving, preserveDmnFormatting } from "./dmn/preserving-writer.js";
|
|
11
11
|
export { sha256Hex } from "./bpmn/sha256.js";
|
|
12
|
+
export { compositeKey, stableToken } from "./types/stable-key.js";
|
|
12
13
|
export { checkDiCompleteness } from "./bpmn/di-check.js";
|
|
13
14
|
export { planeForElement, listPlaneElementIds } from "./bpmn/di-planes.js";
|
|
14
15
|
export { DiagramBuilder, ProcessBuilder } from "./bpmn/bpmn-builder.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assembles the composite key {@link stableToken} hashes.
|
|
3
|
+
*
|
|
4
|
+
* Exported so callers that group or count by key — numbering entities that are
|
|
5
|
+
* genuinely indistinguishable, say — use the same escaping the hash does rather
|
|
6
|
+
* than a second, subtly different join.
|
|
7
|
+
*/
|
|
8
|
+
export declare function compositeKey(segments: readonly string[]): string;
|
|
9
|
+
/**
|
|
10
|
+
* Derives a stable token from an entity's identity.
|
|
11
|
+
*
|
|
12
|
+
* @param prefix - The kind of thing named, e.g. `"Field"` or `"Row"`. It also
|
|
13
|
+
* keeps the result a valid NCName, which a bare digest — free to start with a
|
|
14
|
+
* digit — is not.
|
|
15
|
+
* @param segments - The composite key, most general first: the scope, the
|
|
16
|
+
* entity's type, its own identity, and then any namespace separating this
|
|
17
|
+
* token from another derived for the same entity.
|
|
18
|
+
*/
|
|
19
|
+
export declare function stableToken(prefix: string, segments: readonly string[]): string;
|
|
20
|
+
//# sourceMappingURL=stable-key.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic tokens derived from what an entity *is*, never from where it
|
|
3
|
+
* sits or when it was generated.
|
|
4
|
+
*
|
|
5
|
+
* Generated documents are rebuilt constantly and reviewed as a diff, so the one
|
|
6
|
+
* property that matters is that an unchanged model produces byte-identical
|
|
7
|
+
* output. The two obvious sources both fail it: an incrementing counter moves
|
|
8
|
+
* the moment generation order or array order changes, and `crypto` moves on
|
|
9
|
+
* every run. Hashing a composite key assembled only from the entity's own
|
|
10
|
+
* identity moves when — and only when — that identity does.
|
|
11
|
+
*
|
|
12
|
+
* The key reads `scope:type:identity`, with any further segments distinguishing
|
|
13
|
+
* several tokens derived for one entity — an id *and* a row, say, which must
|
|
14
|
+
* not come out equal. `scope` is the enclosing document or container, so the
|
|
15
|
+
* same field key in two different forms does not collide.
|
|
16
|
+
*/
|
|
17
|
+
import { sha256Hex } from "../bpmn/sha256.js";
|
|
18
|
+
/** Hex digits kept from the digest: 48 bits, far past collision at document scale. */
|
|
19
|
+
const TOKEN_LENGTH = 12;
|
|
20
|
+
/**
|
|
21
|
+
* Escapes the separator, so `["a:b", "c"]` and `["a", "b:c"]` cannot assemble
|
|
22
|
+
* the same key. Without it the composite is ambiguous and two entities that
|
|
23
|
+
* share nothing can still hash alike.
|
|
24
|
+
*/
|
|
25
|
+
function escapeSegment(segment) {
|
|
26
|
+
return segment.replace(/\\/g, "\\\\").replace(/:/g, "\\:");
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Assembles the composite key {@link stableToken} hashes.
|
|
30
|
+
*
|
|
31
|
+
* Exported so callers that group or count by key — numbering entities that are
|
|
32
|
+
* genuinely indistinguishable, say — use the same escaping the hash does rather
|
|
33
|
+
* than a second, subtly different join.
|
|
34
|
+
*/
|
|
35
|
+
export function compositeKey(segments) {
|
|
36
|
+
return segments.map(escapeSegment).join(":");
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Derives a stable token from an entity's identity.
|
|
40
|
+
*
|
|
41
|
+
* @param prefix - The kind of thing named, e.g. `"Field"` or `"Row"`. It also
|
|
42
|
+
* keeps the result a valid NCName, which a bare digest — free to start with a
|
|
43
|
+
* digit — is not.
|
|
44
|
+
* @param segments - The composite key, most general first: the scope, the
|
|
45
|
+
* entity's type, its own identity, and then any namespace separating this
|
|
46
|
+
* token from another derived for the same entity.
|
|
47
|
+
*/
|
|
48
|
+
export function stableToken(prefix, segments) {
|
|
49
|
+
return `${prefix}_${sha256Hex(compositeKey(segments)).slice(0, TOKEN_LENGTH)}`;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=stable-key.js.map
|