@miragon/wardley-dsl 0.5.3 → 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/README.md +38 -0
- package/dist/index.cjs +831 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +43 -6
- package/dist/index.d.ts +43 -6
- package/dist/index.js +830 -77
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -24,6 +24,44 @@ evolve Kettle 0.62`);
|
|
|
24
24
|
const text = serializeDSL(map); // back to OWM text, losslessly
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
### Writing edits back into hand-written text
|
|
28
|
+
|
|
29
|
+
`serializeDSL` writes the canonical form: statements grouped by kind, comments and unknown lines at
|
|
30
|
+
the end, numbers like `0.80` as `0.8`. Where the text file is the source of truth (an editor, a
|
|
31
|
+
file under Git), write an edited map back with `patchDSL` instead:
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { parseDSL, patchDSL } from '@miragon/wardley-dsl';
|
|
35
|
+
|
|
36
|
+
const map = parseDSL(fileText);
|
|
37
|
+
// … the user moves, renames, adds or deletes something …
|
|
38
|
+
const newText = patchDSL(fileText, editedMap);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`patchDSL(originalText, map)` keeps every line the edit did not touch exactly as written (comments,
|
|
42
|
+
blank lines, line order, number formatting, unknown lines, CRLF or LF line breaks and the final line
|
|
43
|
+
break). It rewrites changed statements in place, deletes removed ones together with their links and
|
|
44
|
+
evolve lines, rewrites every line that references a renamed element and inserts new statements after
|
|
45
|
+
the last statement of the same kind. Elements are matched to the source by id, then by name, so the
|
|
46
|
+
element order and ids of `map` do not matter.
|
|
47
|
+
|
|
48
|
+
The result always reads back as the same map as `serializeDSL(map)`. When an edit cannot be patched
|
|
49
|
+
safely into the source layout, `patchDSL` falls back to the canonical `serializeDSL(map)` text (in
|
|
50
|
+
the source's line break style). It never throws.
|
|
51
|
+
|
|
52
|
+
### Ids in the document
|
|
53
|
+
|
|
54
|
+
The OWM DSL writes no ids: the parser derives them from names (`cmp_cup_of_tea`), note texts and
|
|
55
|
+
annotation numbers, with a `_2` suffix for a repeat in line order. An editor that creates or renames
|
|
56
|
+
an element holds an id the text does not give it until the text is read again. `readBackIds(map)`
|
|
57
|
+
tells, by the ids of `map`, which id each element carries once `serializeDSL(map)` is read back:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { readBackIds } from '@miragon/wardley-dsl';
|
|
61
|
+
|
|
62
|
+
readBackIds(editedMap).get('shape_42'); // 'cmp_hot_water'
|
|
63
|
+
```
|
|
64
|
+
|
|
27
65
|
Part of the [Wardley Maps](https://github.com/Miragon/wardley-maps-modeler) monorepo.
|
|
28
66
|
|
|
29
67
|
## License
|