@jylups/flowable-bpmn-moddle 0.1.0-next.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -2
- package/index.js +2 -0
- package/lib/unknown.js +91 -0
- package/package.json +2 -1
- package/resources/flowable.json +98 -0
package/README.md
CHANGED
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Flowable moddle extensions for BPMN 2.0.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Built in Phase 1 of the Flowable BPMN editor ([jylups/bpmn-js-env#7](https://github.com/jylups/bpmn-js-env/issues/7)).
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
npm install @jylups/flowable-bpmn-moddle
|
|
10
|
+
npm install @jylups/flowable-bpmn-moddle
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
@@ -44,6 +44,22 @@ const { xml: saved } = await moddle.toXML(useFlowablePrefix(rootElement));
|
|
|
44
44
|
|
|
45
45
|
Attributes Flowable reads without a namespace (listener, field, in/out and similar sub-attributes, the sequence flow `skipExpression`) are read whether or not they carry a prefix.
|
|
46
46
|
|
|
47
|
+
## Unknown Flowable elements
|
|
48
|
+
|
|
49
|
+
Flowable keeps any extension element it doesn't know, and Flowable Work/Design and users add their own. With the descriptor registered, bpmn-moddle would drop `flowable:*` elements it has no type for. Call `registerUnknownFlowableElements` with the moddle instance before importing, and they are kept and written back unchanged:
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
import { registerUnknownFlowableElements } from '@jylups/flowable-bpmn-moddle';
|
|
53
|
+
|
|
54
|
+
registerUnknownFlowableElements(moddle, xml); // in bpmn-js: modeler.get('moddle')
|
|
55
|
+
|
|
56
|
+
const { rootElement } = await moddle.fromXML(xml, 'bpmn:Definitions');
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The Flowable Work/Design elements seen so far (`work-form-field-validation`, `task-candidates-type`, `static-process-key`, `translation`) are typed.
|
|
60
|
+
|
|
61
|
+
`itemSubjectRef` is kept as text, because Flowable uses values such as `xsd:string` without declaring an `itemDefinition`.
|
|
62
|
+
|
|
47
63
|
## Covered extensions
|
|
48
64
|
|
|
49
65
|
| Area | Extensions |
|
package/index.js
CHANGED
package/lib/unknown.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { FLOWABLE_NS } from './migrate.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Keeps flowable:* elements that the descriptor does not define.
|
|
5
|
+
*
|
|
6
|
+
* Because the Flowable namespace is registered with types, bpmn-moddle drops
|
|
7
|
+
* any flowable:* element it has no type for (an "unknown type" warning).
|
|
8
|
+
* Flowable itself keeps such elements, and Flowable Work/Design and users add
|
|
9
|
+
* their own. Before importing, this function finds the flowable:* element
|
|
10
|
+
* names in the XML that have no type and registers a generic type for each:
|
|
11
|
+
* a text body plus any child elements. Attributes are kept as unknown
|
|
12
|
+
* attributes, as for any element. The element is then read, kept and written
|
|
13
|
+
* back unchanged.
|
|
14
|
+
*
|
|
15
|
+
* Call it with the moddle instance that imports the XML (in bpmn-js:
|
|
16
|
+
* modeler.get('moddle')), before importXML / fromXML. Registered types stay
|
|
17
|
+
* on that instance.
|
|
18
|
+
*
|
|
19
|
+
* @param {Object} moddle - a bpmn-moddle instance with the Flowable descriptor
|
|
20
|
+
* @param {string} xml - the XML that is about to be imported
|
|
21
|
+
*
|
|
22
|
+
* @return {string[]} the names of the types registered, e.g. ['flowable:CustomValue']
|
|
23
|
+
*/
|
|
24
|
+
export function registerUnknownFlowableElements(moddle, xml) {
|
|
25
|
+
const pkg = moddle.getPackage('flowable');
|
|
26
|
+
|
|
27
|
+
if (!pkg) {
|
|
28
|
+
throw new Error('the Flowable descriptor is not registered with this moddle instance');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const registered = [];
|
|
32
|
+
|
|
33
|
+
for (const prefix of flowablePrefixes(xml)) {
|
|
34
|
+
const tag = new RegExp(`<${ escapeRegExp(prefix) }:([A-Za-z_][\\w.-]*)`, 'g');
|
|
35
|
+
|
|
36
|
+
for (const match of xml.matchAll(tag)) {
|
|
37
|
+
const typeName = match[1].charAt(0).toUpperCase() + match[1].slice(1);
|
|
38
|
+
const qualifiedName = `${ pkg.prefix }:${ typeName }`;
|
|
39
|
+
|
|
40
|
+
if (registered.includes(qualifiedName) || hasType(moddle, qualifiedName)) {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
moddle.registry.registerType({
|
|
45
|
+
name: typeName,
|
|
46
|
+
superClass: [ 'Element' ],
|
|
47
|
+
meta: { generic: true },
|
|
48
|
+
properties: [
|
|
49
|
+
{ name: 'body', isBody: true, type: 'String' },
|
|
50
|
+
{ name: 'children', type: 'Element', isMany: true }
|
|
51
|
+
]
|
|
52
|
+
}, pkg);
|
|
53
|
+
|
|
54
|
+
registered.push(qualifiedName);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return registered;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Prefixes the XML binds to the Flowable namespace.
|
|
63
|
+
*
|
|
64
|
+
* @param {string} xml
|
|
65
|
+
*
|
|
66
|
+
* @return {Set<string>}
|
|
67
|
+
*/
|
|
68
|
+
function flowablePrefixes(xml) {
|
|
69
|
+
const prefixes = new Set();
|
|
70
|
+
const declaration = /\sxmlns:([A-Za-z_][\w.-]*)\s*=\s*(["'])([^"']*)\2/g;
|
|
71
|
+
|
|
72
|
+
for (const match of xml.matchAll(declaration)) {
|
|
73
|
+
if (match[3] === FLOWABLE_NS) {
|
|
74
|
+
prefixes.add(match[1]);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return prefixes;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function hasType(moddle, name) {
|
|
82
|
+
try {
|
|
83
|
+
return !!moddle.getType(name);
|
|
84
|
+
} catch {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function escapeRegExp(value) {
|
|
90
|
+
return value.replace(/[.*+?^${}()|[\]\\-]/g, '\\$&');
|
|
91
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jylups/flowable-bpmn-moddle",
|
|
3
|
-
"version": "0.1.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Flowable moddle extensions for BPMN 2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": "./index.js",
|
|
8
8
|
"./lib/migrate.js": "./lib/migrate.js",
|
|
9
|
+
"./lib/unknown.js": "./lib/unknown.js",
|
|
9
10
|
"./resources/flowable.json": "./resources/flowable.json",
|
|
10
11
|
"./package.json": "./package.json"
|
|
11
12
|
},
|
package/resources/flowable.json
CHANGED
|
@@ -1666,6 +1666,104 @@
|
|
|
1666
1666
|
"type": "String"
|
|
1667
1667
|
}
|
|
1668
1668
|
]
|
|
1669
|
+
},
|
|
1670
|
+
{
|
|
1671
|
+
"name": "Work-form-field-validation",
|
|
1672
|
+
"superClass": [
|
|
1673
|
+
"Element"
|
|
1674
|
+
],
|
|
1675
|
+
"meta": {
|
|
1676
|
+
"allowedIn": [
|
|
1677
|
+
"bpmn:StartEvent",
|
|
1678
|
+
"bpmn:UserTask"
|
|
1679
|
+
]
|
|
1680
|
+
},
|
|
1681
|
+
"properties": [
|
|
1682
|
+
{
|
|
1683
|
+
"name": "body",
|
|
1684
|
+
"isBody": true,
|
|
1685
|
+
"type": "String"
|
|
1686
|
+
}
|
|
1687
|
+
]
|
|
1688
|
+
},
|
|
1689
|
+
{
|
|
1690
|
+
"name": "Task-candidates-type",
|
|
1691
|
+
"superClass": [
|
|
1692
|
+
"Element"
|
|
1693
|
+
],
|
|
1694
|
+
"meta": {
|
|
1695
|
+
"allowedIn": [
|
|
1696
|
+
"bpmn:UserTask"
|
|
1697
|
+
]
|
|
1698
|
+
},
|
|
1699
|
+
"properties": [
|
|
1700
|
+
{
|
|
1701
|
+
"name": "body",
|
|
1702
|
+
"isBody": true,
|
|
1703
|
+
"type": "String"
|
|
1704
|
+
}
|
|
1705
|
+
]
|
|
1706
|
+
},
|
|
1707
|
+
{
|
|
1708
|
+
"name": "Static-process-key",
|
|
1709
|
+
"superClass": [
|
|
1710
|
+
"Element"
|
|
1711
|
+
],
|
|
1712
|
+
"meta": {
|
|
1713
|
+
"allowedIn": [
|
|
1714
|
+
"bpmn:CallActivity"
|
|
1715
|
+
]
|
|
1716
|
+
},
|
|
1717
|
+
"properties": [
|
|
1718
|
+
{
|
|
1719
|
+
"name": "body",
|
|
1720
|
+
"isBody": true,
|
|
1721
|
+
"type": "String"
|
|
1722
|
+
}
|
|
1723
|
+
]
|
|
1724
|
+
},
|
|
1725
|
+
{
|
|
1726
|
+
"name": "Translation",
|
|
1727
|
+
"superClass": [
|
|
1728
|
+
"Element"
|
|
1729
|
+
],
|
|
1730
|
+
"meta": {
|
|
1731
|
+
"allowedIn": [
|
|
1732
|
+
"bpmn:BaseElement"
|
|
1733
|
+
]
|
|
1734
|
+
},
|
|
1735
|
+
"properties": [
|
|
1736
|
+
{
|
|
1737
|
+
"name": "key",
|
|
1738
|
+
"isAttr": true,
|
|
1739
|
+
"type": "String"
|
|
1740
|
+
},
|
|
1741
|
+
{
|
|
1742
|
+
"name": "locale",
|
|
1743
|
+
"isAttr": true,
|
|
1744
|
+
"type": "String"
|
|
1745
|
+
},
|
|
1746
|
+
{
|
|
1747
|
+
"name": "body",
|
|
1748
|
+
"isBody": true,
|
|
1749
|
+
"type": "String"
|
|
1750
|
+
}
|
|
1751
|
+
]
|
|
1752
|
+
},
|
|
1753
|
+
{
|
|
1754
|
+
"name": "ItemAwareElement",
|
|
1755
|
+
"isAbstract": true,
|
|
1756
|
+
"extends": [
|
|
1757
|
+
"bpmn:ItemAwareElement"
|
|
1758
|
+
],
|
|
1759
|
+
"properties": [
|
|
1760
|
+
{
|
|
1761
|
+
"name": "bpmn:itemSubjectRef",
|
|
1762
|
+
"isAttr": true,
|
|
1763
|
+
"type": "String",
|
|
1764
|
+
"replaces": "bpmn:ItemAwareElement#itemSubjectRef"
|
|
1765
|
+
}
|
|
1766
|
+
]
|
|
1669
1767
|
}
|
|
1670
1768
|
],
|
|
1671
1769
|
"enumerations": []
|