@miragon/wardley-dsl 0.5.2 → 0.6.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 CHANGED
@@ -24,6 +24,31 @@ 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
+
27
52
  Part of the [Wardley Maps](https://github.com/Miragon/wardley-maps-modeler) monorepo.
28
53
 
29
54
  ## License