@miragon/modeler-api 1.1.0 → 1.3.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 +165 -22
- package/dist/chunk-JK23ZTVG.js +14 -0
- package/dist/chunk-JK23ZTVG.js.map +1 -0
- package/dist/conformance.cjs +290 -7
- package/dist/conformance.cjs.map +1 -1
- package/dist/conformance.d.cts +29 -9
- package/dist/conformance.d.ts +29 -9
- package/dist/conformance.js +286 -8
- package/dist/conformance.js.map +1 -1
- package/dist/index.cjs +11 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +159 -3
- package/dist/index.d.ts +159 -3
- package/dist/index.js +5 -3
- package/package.json +1 -1
- package/dist/chunk-32BMH76T.js +0 -7
- package/dist/chunk-32BMH76T.js.map +0 -1
package/README.md
CHANGED
|
@@ -31,15 +31,15 @@ modeler's build — not a downstream integration review.
|
|
|
31
31
|
import type { CollaborativeModeler } from "@miragon/modeler-api";
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
| Law | Requirement
|
|
35
|
-
| --- |
|
|
36
|
-
| L1 | `importText` is **silent**: no change events, undo history erased without emitting — also over existing history and foreign content; an interaction open during an import (a label editor with typed input) never commits
|
|
37
|
-
| L2 | `exportText` is **canonical**: deterministic, a byte fixpoint on canonical input, idempotent otherwise
|
|
38
|
-
| L3 | `onContentChanged` fires for **every** user-visible change — element commands, config/axis/title edits, undo/redo — and nothing else; inside a listener `exportText()` already returns the new document
|
|
39
|
-
| L4 | undo directly after an import is a defined **no-op** — never a stale-history mutation
|
|
40
|
-
| L5 | view state survives a re-import; an import leaves the view **fitted** to the content; the readback may be a normalised form of what was set
|
|
41
|
-
| L6 | `exportText` is total after a successful import; foreign content is **preserved** through import → export, never dropped, never a throw
|
|
42
|
-
| L7 | EVERY rejected import leaves no trace — previous document still rendered and exported, no events, undo history untouched — and the modeler **stays usable**
|
|
34
|
+
| Law | Requirement |
|
|
35
|
+
| --- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
36
|
+
| L1 | `importText` is **silent**: no change events, undo history erased without emitting — also over existing history and foreign content; an interaction open during an import (a label editor with typed input) never commits |
|
|
37
|
+
| L2 | `exportText` is **canonical**: deterministic, a byte fixpoint on canonical input, idempotent otherwise |
|
|
38
|
+
| L3 | `onContentChanged` fires for **every** user-visible change — element commands, config/axis/title edits, undo/redo — and nothing else; inside a listener `exportText()` already returns the new document |
|
|
39
|
+
| L4 | undo directly after an import is a defined **no-op** — never a stale-history mutation |
|
|
40
|
+
| L5 | view state survives a re-import; an import leaves the view **fitted** to the content; the readback may be a normalised form of what was set; a host's view change (`setViewState`, a fit) never **commits** an open interaction |
|
|
41
|
+
| L6 | `exportText` is total after a successful import; foreign content is **preserved** through import → export, never dropped, never a throw |
|
|
42
|
+
| L7 | EVERY rejected import leaves no trace — previous document still rendered and exported, no events, undo history untouched — and the modeler **stays usable** |
|
|
43
43
|
|
|
44
44
|
View state is never part of the document: `setViewState` fires no change
|
|
45
45
|
events and `exportText` is independent of it.
|
|
@@ -71,6 +71,35 @@ per-instance counter such as `event_1`. An id derived from the content (OWM's
|
|
|
71
71
|
`component_<slug>`) collides only when both users create the same content,
|
|
72
72
|
which the merge has to reconcile anyway.
|
|
73
73
|
|
|
74
|
+
Optional `elements.bounds(id)` (1.2) gives the element's box in DIAGRAM
|
|
75
|
+
coordinates (`{ x, y, width, height }`, the canvas's own space, which zoom and
|
|
76
|
+
scroll leave alone), or `undefined` for an id `list()` does not report. Hosts
|
|
77
|
+
feature-detect it (`typeof modeler.elements?.bounds === "function"`) for
|
|
78
|
+
presence outlines and todo markers instead of reaching into the engine. It
|
|
79
|
+
reads the live canvas: an element created, moved, resized or renamed in the
|
|
80
|
+
session has its current box at once, not the one of the last import. The box
|
|
81
|
+
is the element's own shape (a connection: the box around its waypoints),
|
|
82
|
+
without an external label.
|
|
83
|
+
|
|
84
|
+
Optional `contentBounds()` (1.3) gives the box of the CONTENT in diagram
|
|
85
|
+
coordinates: what a host fits the view to when it fits itself
|
|
86
|
+
(`fitOnImport: false`, the modeler shell's viewport), or `undefined` while
|
|
87
|
+
there is nothing to fit (an empty diagram). Hosts feature-detect it
|
|
88
|
+
(`typeof modeler.contentBounds === "function"`) instead of reaching into a
|
|
89
|
+
renderer's services (Wardley's `panConstraint`). The content is everything the
|
|
90
|
+
canvas draws of the document: the box covers every `elements.bounds` box and
|
|
91
|
+
whatever the notation always draws (Wardley's plot with its axes, so a map
|
|
92
|
+
without components still has a box and `undefined` is no emptiness test). It
|
|
93
|
+
is tight, with no padding of its own: a host's fit adds its margins. Like
|
|
94
|
+
`elements.bounds` it ignores zoom and scroll, reads the live canvas, and before
|
|
95
|
+
the first import returns `undefined` or a box without throwing. A browser
|
|
96
|
+
measures SVG text differently at each zoom (Chromium lays it out at the scaled
|
|
97
|
+
font size), so a renderer computes the box from its model, or measures it once
|
|
98
|
+
per content change and keeps it across view changes. A viewer that exposes it
|
|
99
|
+
follows the same rules. It sits on the modeler next to the view state rather
|
|
100
|
+
than on `elements`: a fit frames the whole canvas, and a notation without
|
|
101
|
+
addressable elements still has content to fit.
|
|
102
|
+
|
|
74
103
|
An interaction in progress during an import (an open label editor, a popup
|
|
75
104
|
with typed input) never commits during or because of it (L1): no change
|
|
76
105
|
event, nothing in the imported document or on its undo history, nothing
|
|
@@ -78,6 +107,68 @@ applied to an element the import removed. RECOMMENDED: keep the typed input
|
|
|
78
107
|
and reopen the interaction on the element with the same id when it is still
|
|
79
108
|
there — hosts re-import remote states while the user is typing.
|
|
80
109
|
|
|
110
|
+
A view change the HOST makes — `setViewState`, or a fit its chrome applies to
|
|
111
|
+
the canvas — never commits an interaction in progress either (L5, since 1.2):
|
|
112
|
+
no change event, the export unchanged. Hosts restore the viewport after every
|
|
113
|
+
remote re-import and refit when their chrome changes; a modeler that completes
|
|
114
|
+
its label editor on every viewbox change (diagram-js's direct-editing pattern,
|
|
115
|
+
which every renderer built against contract 1.1 follows) writes the half-typed
|
|
116
|
+
label into the shared document for every peer. RECOMMENDED: the interaction
|
|
117
|
+
stays open with its typed input, so the user's commit afterwards writes what it
|
|
118
|
+
would have written without the view change.
|
|
119
|
+
|
|
120
|
+
## Factory options
|
|
121
|
+
|
|
122
|
+
`CollaborativeModelerOptions` (1.2) names the options a host has to feed a
|
|
123
|
+
renderer's contract factory (`createCollaborativeModeler`,
|
|
124
|
+
`createCollaborativeViewer`), the same for every notation, so a host can pass
|
|
125
|
+
every notation one object. The contract defines them; each renderer adopts
|
|
126
|
+
them in its own release, next to its own options (diagram-js
|
|
127
|
+
`additionalModules`). Adopting them is part of moving a renderer to contract
|
|
128
|
+
1.2: `meta.apiVersion` follows the `@miragon/modeler-api` version the renderer
|
|
129
|
+
pins, and no kit case checks the options (the harness's `create()` builds the
|
|
130
|
+
instance), so a renderer that reports 1.2.0 without them silently ignores a
|
|
131
|
+
host's aligned options.
|
|
132
|
+
|
|
133
|
+
| Option | Meaning | Default |
|
|
134
|
+
| -------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------- |
|
|
135
|
+
| `freeArea` | the part of the canvas no host chrome covers — `{ insets }` (px from the container's edges, e.g. `shell.fitInsets()`) or `{ center }` (diagram coordinates, e.g. `viewport.freeRectCenter()`), each a function, never both; keyboard creation lands in its centre | the whole container |
|
|
136
|
+
| `fitOnImport` | fit the content after every import (the fitted view of L5), into the free rectangle or with the renderer's own padding (see below); `false` when the host's chrome fits it itself | `true` |
|
|
137
|
+
| `undoRedoKeys` | bind Cmd/Ctrl+Z, Cmd/Ctrl+Shift+Z and Cmd/Ctrl+Y to the canvas history; `false` when the host owns the document's history (VS Code) | `true` |
|
|
138
|
+
|
|
139
|
+
```ts
|
|
140
|
+
import type { CollaborativeModelerOptions } from "@miragon/modeler-api";
|
|
141
|
+
|
|
142
|
+
const options: CollaborativeModelerOptions = {
|
|
143
|
+
freeArea: { insets: () => shell.fitInsets() }, // or { center: () => viewport.freeRectCenter() }
|
|
144
|
+
fitOnImport: false, // the shell's viewport fits after every import
|
|
145
|
+
undoRedoKeys: false, // VS Code owns the history
|
|
146
|
+
};
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Until a renderer ships the aligned names, a host keeps passing that
|
|
150
|
+
renderer's own names, or passes both: a renderer that accepts the aligned
|
|
151
|
+
names takes them over its own. Its own names then stay accepted as DEPRECATED
|
|
152
|
+
aliases for one minor release of that renderer, then go: `freeRectInsets`
|
|
153
|
+
(Wardley, Event Storming, Context Maps) is `freeArea: { insets }`,
|
|
154
|
+
`freeRectCenter` (Team Topologies, Value Chain) is `freeArea: { center }`, and
|
|
155
|
+
Wardley's `keyboard: { undoRedo }` is `undoRedoKeys`. A renderer given only
|
|
156
|
+
`center` that needs the rectangle itself (a pan constraint) works there as it
|
|
157
|
+
does without the option: no host chrome, with whatever margins of its own it
|
|
158
|
+
uses then. A viewer factory takes the same type and ignores `undoRedoKeys`.
|
|
159
|
+
The kit's `create()` keeps `fitOnImport` at its default: L5 checks the
|
|
160
|
+
modeler's own fit.
|
|
161
|
+
|
|
162
|
+
The post-import fit (`fitOnImport`, L5's fitted view) MAY use the free area:
|
|
163
|
+
given `insets` a renderer may fit into the free rectangle (Wardley, Context
|
|
164
|
+
Maps) or keep its own fit (Event Storming, Team Topologies, Value Chain), and
|
|
165
|
+
given only `center`, which names no rectangle, it MAY fit as it does without
|
|
166
|
+
the option, keeping the padding it uses then (Context Maps keeps the room its
|
|
167
|
+
palette needs, and a test pins it). All five published renderers conform to
|
|
168
|
+
this reading; no kit case checks it, since `create()` takes no options. A host
|
|
169
|
+
whose first view must leave its chrome free passes `fitOnImport: false` and
|
|
170
|
+
fits itself, to `contentBounds()` where the renderer has it.
|
|
171
|
+
|
|
81
172
|
## The conformance kit
|
|
82
173
|
|
|
83
174
|
```ts
|
|
@@ -98,9 +189,11 @@ registerConformance(
|
|
|
98
189
|
configMutations: [{ name: "axis labels", run: (m) => renameEvolutionAxis(m) }], // [] if the notation has none
|
|
99
190
|
undo: (m) => triggerUndo(m),
|
|
100
191
|
redo: (m) => triggerRedo(m),
|
|
192
|
+
moveElement: (m) => dragFirstElement(m), // optional: move one element by its own commands, return its id
|
|
101
193
|
probeTexts: [CUT_OFF_SAMPLE], // optional: damaged forms your parser meets, on top of the derived probes
|
|
102
194
|
openInteraction: (m) => typeIntoLabelEditor(m, "typed, not committed"), // open an editor, type, do NOT commit
|
|
103
195
|
interactionState: (m) => readOpenLabelEditor(m), // { elementId, text } | undefined
|
|
196
|
+
commitInteraction: (m) => pressEnterInLabelEditor(m), // optional: commit what openInteraction typed
|
|
104
197
|
// engines that debounce change delivery: make this outlast the debounce
|
|
105
198
|
settle: () => new Promise((r) => setTimeout(r, 50)),
|
|
106
199
|
},
|
|
@@ -126,7 +219,14 @@ to route it) instead of passing. An explicit `[]` (`invalidTexts`,
|
|
|
126
219
|
`foreignTexts`, `configMutations`, `looseTexts`) is a statement that the
|
|
127
220
|
notation has no such form and skips nothing. Without `openInteraction` the
|
|
128
221
|
L1 interaction case reports a skip; with `openInteraction` but without
|
|
129
|
-
`interactionState` only its keep-and-reopen half does.
|
|
222
|
+
`interactionState` only its keep-and-reopen half does. A modeler without
|
|
223
|
+
`elements.bounds` skips the bounds case; with it, a harness without
|
|
224
|
+
`moveElement` skips only its move half, one without `viewState` only its
|
|
225
|
+
diagram-coordinates half. A modeler without `contentBounds` skips the
|
|
226
|
+
content-bounds case; with it, a harness without `viewState` skips only its
|
|
227
|
+
view half, and a modeler without `elements.bounds` only its covering half.
|
|
228
|
+
Without `openInteraction` or `viewState` the L5 interaction case reports a
|
|
229
|
+
skip; without `commitInteraction` only its commit halves do.
|
|
130
230
|
|
|
131
231
|
**Every rejection is probed.** `invalidTexts` lists what MUST reject; the kit
|
|
132
232
|
does not take `[]` on trust. The L7 probe case derives damaged forms from
|
|
@@ -155,19 +255,30 @@ requires no change event, the imported document as the export and an undo
|
|
|
155
255
|
that changes nothing (L1, L4). `interactionState` lets it check the
|
|
156
256
|
recommended keep-and-reopen on the same-document import.
|
|
157
257
|
|
|
258
|
+
**Interactions open during a host's view change.** On a fresh import of
|
|
259
|
+
`canonicalTexts[0]` the kit opens the interaction, commits it with
|
|
260
|
+
`commitInteraction` and requires the export to change and to contain the typed
|
|
261
|
+
input (`interactionState().text`) — proof the case can see a commit. It then
|
|
262
|
+
re-imports, opens the interaction again and calls `setViewState(viewState)`:
|
|
263
|
+
no change event, the export unchanged (L5), and the view really changed. The
|
|
264
|
+
RECOMMENDED keep-open is an advisory: `interactionState` must still report the
|
|
265
|
+
same element and input, and `commitInteraction` must then write the same
|
|
266
|
+
document as without the view change — so `openInteraction` types the same
|
|
267
|
+
input on every call.
|
|
268
|
+
|
|
158
269
|
**Recommendations are advisories.** Where the contract only RECOMMENDS
|
|
159
|
-
(collision-free ids across peers, keep-and-reopen of an open interaction
|
|
160
|
-
|
|
161
|
-
(`console.warn` by default) and never
|
|
162
|
-
with a failing case, only in a major
|
|
163
|
-
same canonical text into two fresh
|
|
164
|
-
|
|
165
|
-
same name and the id spells it out
|
|
166
|
-
name's, as `component_new_component` does
|
|
167
|
-
derived from the content and collides for
|
|
168
|
-
the check reports a skip instead: let
|
|
169
|
-
(a counter the harness shares across
|
|
170
|
-
does).
|
|
270
|
+
(collision-free ids across peers, keep-and-reopen of an open interaction across
|
|
271
|
+
an import, keep-open across a host's view change), the kit reports what it
|
|
272
|
+
finds as an ADVISORY through `onAdvisory` (`console.warn` by default) and never
|
|
273
|
+
fails: a recommendation becomes a law, with a failing case, only in a major
|
|
274
|
+
release. The collision check imports the same canonical text into two fresh
|
|
275
|
+
instances, runs `mutate` once on each and advises when both allocate the same
|
|
276
|
+
id — unless both new elements carry the same name and the id spells it out
|
|
277
|
+
(its letters and digits contain the name's, as `component_new_component` does
|
|
278
|
+
for "New Component"). Such an id is derived from the content and collides for
|
|
279
|
+
identical content by design, so the check reports a skip instead: let
|
|
280
|
+
`mutate`'s elements differ in content (a counter the harness shares across
|
|
281
|
+
instances, as the reference harness does).
|
|
171
282
|
|
|
172
283
|
**View state is compared by readback.** The kit never compares
|
|
173
284
|
`getViewState()` with your `viewState` literal: it sets it, reads the
|
|
@@ -175,6 +286,24 @@ modeler's own (possibly normalised) state back, and requires that readback
|
|
|
175
286
|
to survive a re-import — a diagram-js viewbox that comes back rounded with
|
|
176
287
|
`scale`/`inner`/`outer` is fine.
|
|
177
288
|
|
|
289
|
+
**Element boxes are verified live.** With `elements.bounds` present, every
|
|
290
|
+
listed id must give a finite box with a non-negative size and an unknown id
|
|
291
|
+
`undefined` — after an import, after `mutate` (the new element has its box at
|
|
292
|
+
once) and after `moveElement` (the moved element's box changed position).
|
|
293
|
+
`setViewState(viewState)` must leave every box as it was: they are diagram
|
|
294
|
+
coordinates. A viewer that exposes `bounds` is held to the same listing rules.
|
|
295
|
+
|
|
296
|
+
**The content box is verified around every element.** With `contentBounds`
|
|
297
|
+
present, it must not throw and must give `undefined` or a finite box with a
|
|
298
|
+
non-negative size before the first import; after importing each canonical text
|
|
299
|
+
and after `mutate` it must give a finite box as soon as an element is listed,
|
|
300
|
+
and that box must cover every element's finite `elements.bounds` box (the new
|
|
301
|
+
element included, so a box measured at the last import fails), give or take
|
|
302
|
+
what float32 rounding takes off a box measured on the live SVG (`getBBox`): a
|
|
303
|
+
thousandth of a unit, or 2^-20 of the edge where that is more.
|
|
304
|
+
`setViewState(viewState)` must leave it as it was. A viewer that exposes `contentBounds` is held to the
|
|
305
|
+
same rules after an import.
|
|
306
|
+
|
|
178
307
|
**Element identity is verified through names.** After an unrelated edit, and
|
|
179
308
|
after an export → import into the same instance, a fresh instance and the
|
|
180
309
|
viewer, every id the session reported must still exist and, where the
|
|
@@ -198,6 +327,16 @@ rewrites the constant on every release (`extra-files`) and a test pins it to
|
|
|
198
327
|
`meta.apiVersion`; hosts match on the major (`apiVersionsCompatible`).
|
|
199
328
|
Releases are tagged `modeler-api-vX.Y.Z`.
|
|
200
329
|
|
|
330
|
+
Hosts bind from the package root, which carries no kit code (since 1.2;
|
|
331
|
+
`@miragon/modeler-api/conformance` re-exports `apiVersionsCompatible`, so 1.1
|
|
332
|
+
imports keep working):
|
|
333
|
+
|
|
334
|
+
```ts
|
|
335
|
+
import { apiVersionsCompatible, MODELER_API_VERSION } from "@miragon/modeler-api";
|
|
336
|
+
|
|
337
|
+
if (!apiVersionsCompatible(modeler.meta.apiVersion, MODELER_API_VERSION)) refuseToMount(modeler);
|
|
338
|
+
```
|
|
339
|
+
|
|
201
340
|
The contract is first published as 1.0.0, never 0.x: under 0.x,
|
|
202
341
|
`apiVersionsCompatible` matches on the minor too, which would turn every
|
|
203
342
|
additive surface into a lockstep release across all modelers and their
|
|
@@ -226,6 +365,10 @@ Recommendations today, proposed as hard laws for the next major:
|
|
|
226
365
|
during an import is reopened, with its typed input, on the element with the
|
|
227
366
|
same id when that element is still there (today: L1 RECOMMENDED, advisory in
|
|
228
367
|
the L1 interaction case).
|
|
368
|
+
- **Keep an interaction open across a host's view change** — after
|
|
369
|
+
`setViewState` (or a host's fit) the interaction is still open with its typed
|
|
370
|
+
input, and the user's commit writes what it would have written without the
|
|
371
|
+
view change (today: L5 RECOMMENDED, advisory in the L5 interaction case).
|
|
229
372
|
|
|
230
373
|
## License
|
|
231
374
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
var MODELER_API_VERSION = "1.3.0";
|
|
3
|
+
function apiVersionsCompatible(a, b) {
|
|
4
|
+
const [aMajor = "", aMinor = ""] = a.split(".");
|
|
5
|
+
const [bMajor = "", bMinor = ""] = b.split(".");
|
|
6
|
+
if (aMajor !== bMajor) return false;
|
|
7
|
+
return aMajor !== "0" || aMinor === bMinor;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export {
|
|
11
|
+
MODELER_API_VERSION,
|
|
12
|
+
apiVersionsCompatible
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=chunk-JK23ZTVG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * @miragon/modeler-api — ONE interface every Miragon modeler implements.\n *\n * The contract encodes, as REQUIREMENTS, the behavioral drift that had to be\n * discovered per modeler against engine internals before it existed:\n * an `importDSL` that emitted change events (rewriting hand-authored files on\n * open), an import that left the undo stack on stale removed shapes, a\n * serializer that was not a byte fixpoint. A host embedding a conforming\n * modeler needs no per-engine suppression tricks — the laws below hold.\n *\n * The conformance test kit (`@miragon/modeler-api/conformance`) turns each\n * law into an executable case the modeler repo runs in its own CI.\n */\n\n/** the semver of THIS contract — a modeler declares the version it implements\n * in `meta.apiVersion`; hosts check compatibility with `apiVersionsCompatible`\n * (same major; while 0.x, the same minor too). The constant IS the\n * package version: release-please rewrites the literal below on every\n * release (release-please-config.json `extra-files`), and the kit's own\n * test pins it to package.json exactly. Modelers pin the npm package; the\n * constant is what travels in `meta`. */\nexport const MODELER_API_VERSION = \"1.3.0\"; // x-release-please-version\n\n/**\n * apiVersion compatibility: same major — and, while the contract is 0.x,\n * the same minor too (pre-1.0 minors may break; bump-minor-pre-major).\n * Hosts call it at bind time with `meta.apiVersion` and their own\n * MODELER_API_VERSION; it lives in the package root so that check never\n * pulls the conformance kit into a host bundle (`/conformance` re-exports it)\n */\nexport function apiVersionsCompatible(a: string, b: string): boolean {\n const [aMajor = \"\", aMinor = \"\"] = a.split(\".\");\n const [bMajor = \"\", bMinor = \"\"] = b.split(\".\");\n if (aMajor !== bMajor) return false;\n return aMajor !== \"0\" || aMinor === bMinor;\n}\n\nexport interface ModelerMeta {\n /** stable notation id, e.g. \"wardley\", \"team-topology\", \"event-storming\" */\n readonly notation: string;\n /** the MODELER_API_VERSION this modeler implements — compatible when the\n * major matches and, while the contract is 0.x, the minor too (pre-1.0\n * minors may break: bump-minor-pre-major) */\n readonly apiVersion: string;\n /**\n * true on an editing mount (the package's Modeler), false on a VIEWER\n * (its NavigatedViewer/Viewer): a viewer never fires `onContentChanged`,\n * accepts no user commands, and still imports, exports, reveals and\n * reports view state exactly like the editor — hosts mount it on\n * read-only surfaces (an MCP-App widget in read-only mode) without\n * per-package knowledge or a command-stack shim.\n */\n readonly editable: boolean;\n}\n\nexport interface ImportResult {\n /** non-fatal notes from the import (unknown lines kept, migrations run) */\n warnings: string[];\n}\n\nexport interface ElementInfo {\n /**\n * stable element id — identical across re-imports of the same text AND\n * untouched by edits to OTHER elements: hosts anchor todos, presence and\n * `?element=` deep links to it, so an id that renumbers when a line is\n * inserted above (positional edge ids) breaks every anchor below it. An\n * element without an id in the text gets one the serializer WRITES BACK.\n *\n * The id a session reports IS the element's id in the document: after\n * `exportText()` → `importText()` — in this instance or in any other one\n * (a peer, the viewer, the next session) — the element carries the same\n * id. An id that lives only in memory anchors nothing: the todo or deep\n * link a host stored against it points nowhere once the text travels.\n *\n * RECOMMENDED: when two peers create different elements at the same time,\n * their ids do not collide. An id allocated regardless of the content —\n * a per-instance counter (`event_1` on both peers) — does: once both edits\n * merge into one document, two elements share one id; random or\n * peer-scoped ids do not. An id derived from the content (OWM's\n * `component_<slug>`) collides only when both users create the same\n * content, which the merge has to reconcile anyway.\n */\n id: string;\n /** human label, when the notation has one */\n name?: string;\n}\n\n/** a box in diagram coordinates: an element's, as `ElementsSurface.bounds`\n * reports it, or the content's, as `CollaborativeModeler.contentBounds` does */\nexport interface ElementBounds {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/**\n * Optional element surface — what a host needs for anchored todos, `?element=`\n * deep links and the selection half of live presence. Absent = the notation\n * has no addressable element identity. Ids are ELEMENT ids throughout: a\n * shape that only labels another element (diagram-js external labels) is\n * reported and revealed as its target, never under its own label id.\n */\nexport interface ElementsSurface {\n /** every addressable element currently on the canvas */\n list(): ElementInfo[];\n /** select + scroll the element into view; false when the id is unknown.\n * Revealing is view behavior: it delivers a selection, never a change event */\n reveal(id: string): boolean;\n /** the current selection as stable element ids — synchronous, so a host\n * can read it at the moment of a click (a deep link carrying the\n * selection) without caching every delivery */\n selection(): string[];\n /** selection changes as STABLE element ids; returns the unsubscribe */\n onSelection(cb: (ids: string[]) => void): () => void;\n /**\n * the element's box in DIAGRAM coordinates — the canvas's own coordinate\n * space, which zoom and scroll leave alone (a host maps it to the screen\n * with the current view, or draws in a layer that moves with the canvas) —\n * or `undefined` for an id `list()` does not report. Optional (1.2): hosts\n * feature-detect it for presence outlines and todo markers instead of\n * reaching into the engine.\n *\n * It reads the LIVE canvas: an element created, moved, resized or renamed\n * in this session has its current box at once, not the one of the last\n * import — a host outlining a peer's selection would otherwise draw it\n * where the element was, or not at all, until the next import. The box is\n * the element's own shape (a connection: the box around its waypoints); an\n * external label is not part of it.\n */\n bounds?(id: string): ElementBounds | undefined;\n}\n\n/**\n * The collaborative-modeler contract. The LAWS (verified by the conformance\n * kit) are part of the interface:\n *\n * L1 SILENT IMPORT — `importText` never fires `onContentChanged` and erases\n * the undo history without emitting — also when history exists. Hosts\n * re-import remote states on every sync; an import echo would re-export\n * the canonical serialization over half-typed peer text.\n * An interaction in progress when an import runs (an open label editor,\n * a popup with typed input) never commits during or because of the\n * import: no change event comes from it, its input lands neither in the\n * imported document nor on its fresh undo history, and nothing is\n * applied to an element the import removed. RECOMMENDED: keep the typed\n * input and reopen the interaction on the element with the same id when\n * that element is still there after the import — a remote re-import\n * should not cost the user what they were typing.\n * L2 CANONICAL FIXPOINT — `exportText` is deterministic, and for any text t:\n * with c = exportText() after importText(t), importText(c) followed by\n * exportText() returns c byte-for-byte. Canonicalization is idempotent;\n * opening a file never rewrites it.\n * L3 ONE CHANGE EVENT — every user-visible atomic change (element commands\n * AND config/axis/title/style edits that live in the document, AND\n * undo/redo) fires `onContentChanged` at least once, and nothing else\n * does: not `importText`, not undo-history housekeeping, not view or\n * selection changes. When a listener runs, `exportText()` ALREADY\n * returns the post-change serialization — hosts export inside the\n * listener; an emit-before-apply would lose the last edit.\n * L4 DEFINED UNDO ACROSS IMPORTS — undo directly after an `importText` is a\n * no-op: it must never mutate or resurrect shapes from the pre-import\n * document (id coincidence included).\n * L5 VIEW-STATE ROUND-TRIP — `getViewState`/`setViewState` survive a\n * re-import: snapshot before, restore after, viewport unchanged. An\n * import leaves the view FITTED to the content (the defined post-import\n * view, the same for the same document and host — a host that wants to\n * keep the user's viewport across a remote re-import snapshots before\n * and restores after, and one that fits the view itself passes\n * `fitOnImport: false` and fits to `contentBounds()`, 1.3, where the\n * modeler has it); before the first import `getViewState()` returns\n * `undefined` or a state `setViewState` accepts, and never throws. The\n * readback may be a NORMALISED form of what was set (a diagram-js\n * viewbox comes back rounded, with scale/inner/outer) — what must hold\n * is that setting a readback yields that readback again.\n * A view change the HOST makes — `setViewState`, or a fit its chrome\n * applies to the canvas — never commits an interaction in progress (an\n * open label editor, a popup with typed input): no change event, the\n * export unchanged. Hosts restore the viewport after every remote\n * re-import and refit when their chrome changes; a commit there writes\n * the half-typed input into the shared document for every peer.\n * RECOMMENDED: the interaction stays open with its typed input, so the\n * user's own commit afterwards writes what it would have written without\n * the view change.\n * L6 EXPORT IS TOTAL AFTER IMPORT — after a successful import (and any\n * sequence of user commands and undos), `exportText` succeeds. Foreign or\n * auxiliary content the modeler does not understand is PRESERVED through\n * import → export (it comes back in the export, canonicalised like the\n * rest), never dropped and never a reason to throw.\n * L7 REJECTED IMPORTS LEAVE NO TRACE — `importText` on non-importable text\n * REJECTS (resolve-with-warnings means \"imported, with notes\"; rejection\n * means \"nothing imported\"). This holds for EVERY rejection, whatever\n * the input (a truncated or half-typed text included): afterwards the\n * previously imported document is still rendered with its elements,\n * `exportText` still returns it, no change event has fired and the undo\n * history is untouched.\n * The modeler stays USABLE: the next valid import renders, the next user\n * command applies. Hosts re-import half-typed peer text on every sync —\n * \"blank (or wedged) until healed\" is not an acceptable failure mode.\n *\n * View state is NEVER part of the document: `setViewState` fires no change\n * events and `exportText` is independent of it.\n */\nexport interface CollaborativeModeler {\n readonly meta: ModelerMeta;\n\n /** mount the canvas into a host element (once, before the first import).\n * The host must be attached to the document with a non-zero size — a\n * detached or 0×0 element gives diagram-js engines NaN viewboxes.\n * Calls made between mounting and the first import (`exportText()`, a\n * user command) return whatever the modeler defines, or throw (only\n * `getViewState` never does, L5), but they never wedge the instance:\n * the first `importText` still behaves exactly as specified */\n attachTo(host: Element): void;\n\n /** parse + render `text` — SILENT per L1, the view fitted to the content\n * per L5; resolves when rendered, REJECTS when nothing was imported (L7).\n * This holds for the first import too, whatever was called before it — a\n * host may export or route a command before its first document arrives */\n importText(text: string): Promise<ImportResult>;\n\n /** the canonical serialization of the current document (L2, L6) */\n exportText(): string;\n\n /** subscribe to user-visible model changes (L3); returns the unsubscribe */\n onContentChanged(cb: () => void): () => void;\n\n /** opaque viewport snapshot (zoom/scroll) — JSON-serializable (L5) */\n getViewState(): unknown;\n setViewState(state: unknown): void;\n\n /**\n * the box of the CONTENT in diagram coordinates — what a host fits the\n * view to when it fits itself (`fitOnImport: false`, the modeler shell's\n * viewport) — or `undefined` while there is nothing to fit (an empty\n * diagram). Optional (1.3): hosts feature-detect it (`typeof\n * modeler.contentBounds === \"function\"`) instead of reaching into a\n * renderer's services; a renderer's own fit stays its business (L5).\n *\n * The content is everything the canvas draws of the document: the box\n * covers every box `elements.bounds` reports, and whatever the notation\n * always draws (Wardley's plot with its axes — a map without components\n * still has a box, so `undefined` is no emptiness test). It is tight: no\n * padding and no room for chrome of its own, since a host's fit adds its\n * margins (the shell's fit insets) on top. Like `elements.bounds` it is in\n * the canvas's own coordinate space, which zoom and scroll leave alone,\n * and it reads the LIVE canvas: an element created or moved in this\n * session counts at once. A browser measures SVG text differently at each\n * zoom (Chromium lays it out at the scaled font size), so a renderer\n * computes the box from its model, or measures it once per content change\n * and keeps it across view changes. Before the first import it returns\n * `undefined` or a box, and never throws. A viewer that exposes it follows\n * the same rules. It sits next to the view state rather than on `elements`: a fit\n * frames the whole canvas, and a notation without addressable elements\n * still has content to fit.\n */\n contentBounds?(): ElementBounds | undefined;\n\n readonly elements?: ElementsSurface;\n\n /** tear down DOM + listeners; further calls on the instance are undefined\n * behavior, but a second destroy() must not throw */\n destroy(): void;\n}\n\n/** px the host's chrome covers along the edges of the modeler's container */\nexport interface FreeAreaInsets {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\n\n/** a point in diagram coordinates */\nexport interface DiagramPoint {\n x: number;\n y: number;\n}\n\n/**\n * The FREE AREA: the part of the canvas no host chrome covers (Miragon\n * guide §5.9). Keyboard creation places a new element in its centre (§5.5)\n * and a renderer that constrains panning keeps the content reachable around\n * it, so both agree with a host that fits into the same rectangle. A host\n * passes ONE of two forms, each a function the renderer reads whenever it\n * needs it (the chrome changes when an inspector or a legend opens):\n *\n * - `insets`: what the chrome covers, in px from the container's edges\n * (the modeler shell's `shell.fitInsets()`); the renderer computes the\n * centre itself, the way a fit does;\n * - `center`: the centre itself, in diagram coordinates, `undefined` while\n * there is none (a 0×0 container) — the shell's `viewport.freeRectCenter()`.\n *\n * A renderer accepts both. One that needs the rectangle itself (a pan\n * constraint) and is given only `center` works there as it does without\n * the option: it assumes no host chrome, with whatever margins of its own\n * it uses then.\n *\n * The post-import fit (`fitOnImport`, L5's fitted view) MAY use the free\n * area: given `insets` a renderer may fit into the free rectangle or keep\n * its own fit, and given only `center`, which names no rectangle, it MAY fit\n * as it does without the option, keeping the padding it uses then (Context\n * Maps keeps the room its palette needs) — the reading all five published\n * renderers conform to, which no kit case checks; a host whose first view\n * must leave its chrome free passes `fitOnImport: false` and fits itself.\n */\nexport type FreeArea =\n | { insets: () => FreeAreaInsets; center?: never }\n | { center: () => DiagramPoint | undefined; insets?: never };\n\n/**\n * The options a renderer's contract factory takes under THESE names once it\n * implements contract 1.2, so a host feeds every notation the same object\n * instead of one spelling per renderer. A renderer extends the type with its\n * own options (diagram-js `additionalModules`); the contract fixes names,\n * meaning and defaults. A viewer factory takes the same type and ignores\n * what has no meaning without editing (`undoRedoKeys`).\n *\n * Each renderer adopts them in its own release, as part of its move to 1.2:\n * `meta.apiVersion` follows the pinned package and no kit case checks the\n * options, so the version alone does not tell a host they are honoured.\n * Until a renderer ships them, a host passes the renderer's own names, or\n * both. Those names then stay accepted as DEPRECATED aliases for one minor\n * release of that renderer, then go: `freeRectInsets` (Wardley, Event\n * Storming, Context Maps) is `freeArea: { insets }`, `freeRectCenter` (Team\n * Topologies, Value Chain) is `freeArea: { center }`, and Wardley's\n * `keyboard: { undoRedo }` is `undoRedoKeys`. Given both, the aligned name\n * wins.\n */\nexport interface CollaborativeModelerOptions {\n /** where the host's chrome leaves the canvas free; default: the whole container */\n freeArea?: FreeArea | undefined;\n /**\n * fit the content into the view after every import — default true, the\n * fitted view L5 defines. A host whose chrome fits the content itself\n * (the modeler shell's viewport fits into the free area) passes false:\n * the post-import view is then the host's to set, and L5's fit is the\n * host's fit. The conformance kit runs with the default. Whether the\n * renderer's own fit uses `freeArea` is its choice (see `FreeArea`): with\n * `insets` it may fit into the free rectangle, with only `center` it may\n * keep the padding it uses without the option\n */\n fitOnImport?: boolean | undefined;\n /**\n * bind Cmd/Ctrl+Z, Cmd/Ctrl+Shift+Z and Cmd/Ctrl+Y to the canvas history —\n * default true. A host that owns the document's history (VS Code) passes\n * false, and the keys reach it unprevented; text fields keep their own\n * undo either way\n */\n undoRedoKeys?: boolean | undefined;\n}\n"],"mappings":";AAqBO,IAAM,sBAAsB;AAS5B,SAAS,sBAAsB,GAAW,GAAoB;AACnE,QAAM,CAAC,SAAS,IAAI,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG;AAC9C,QAAM,CAAC,SAAS,IAAI,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG;AAC9C,MAAI,WAAW,OAAQ,QAAO;AAC9B,SAAO,WAAW,OAAO,WAAW;AACtC;","names":[]}
|
package/dist/conformance.cjs
CHANGED
|
@@ -28,7 +28,13 @@ __export(conformance_exports, {
|
|
|
28
28
|
module.exports = __toCommonJS(conformance_exports);
|
|
29
29
|
|
|
30
30
|
// src/index.ts
|
|
31
|
-
var MODELER_API_VERSION = "1.
|
|
31
|
+
var MODELER_API_VERSION = "1.3.0";
|
|
32
|
+
function apiVersionsCompatible(a, b) {
|
|
33
|
+
const [aMajor = "", aMinor = ""] = a.split(".");
|
|
34
|
+
const [bMajor = "", bMinor = ""] = b.split(".");
|
|
35
|
+
if (aMajor !== bMajor) return false;
|
|
36
|
+
return aMajor !== "0" || aMinor === bMinor;
|
|
37
|
+
}
|
|
32
38
|
|
|
33
39
|
// src/conformance.ts
|
|
34
40
|
function attachedHost(width = 800, height = 600) {
|
|
@@ -40,12 +46,6 @@ function attachedHost(width = 800, height = 600) {
|
|
|
40
46
|
document.body.append(wrapper);
|
|
41
47
|
return host;
|
|
42
48
|
}
|
|
43
|
-
function apiVersionsCompatible(a, b) {
|
|
44
|
-
const [aMajor = "", aMinor = ""] = a.split(".");
|
|
45
|
-
const [bMajor = "", bMinor = ""] = b.split(".");
|
|
46
|
-
if (aMajor !== bMajor) return false;
|
|
47
|
-
return aMajor !== "0" || aMinor === bMinor;
|
|
48
|
-
}
|
|
49
49
|
function fail(message) {
|
|
50
50
|
throw new Error(`modeler-api conformance: ${message}`);
|
|
51
51
|
}
|
|
@@ -58,6 +58,68 @@ function exportOrFail(modeler, when) {
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
var same = (a, b) => JSON.stringify(a) === JSON.stringify(b);
|
|
61
|
+
var hasBounds = (elements) => typeof elements.bounds === "function";
|
|
62
|
+
var isFiniteBox = (box) => box !== void 0 && [box.x, box.y, box.width, box.height].every((n) => typeof n === "number" && Number.isFinite(n)) && box.width >= 0 && box.height >= 0;
|
|
63
|
+
var describeBox = (box) => box === void 0 ? "undefined" : `{ x: ${box.x}, y: ${box.y}, width: ${box.width}, height: ${box.height} }`;
|
|
64
|
+
var hasContentBounds = (m) => typeof m.contentBounds === "function";
|
|
65
|
+
var edgeTolerance = (edge) => Math.max(1e-3, Math.abs(edge) * 2 ** -20);
|
|
66
|
+
var covers = (outer, inner) => {
|
|
67
|
+
const right = outer.x + outer.width;
|
|
68
|
+
const bottom = outer.y + outer.height;
|
|
69
|
+
return inner.x >= outer.x - edgeTolerance(outer.x) && inner.y >= outer.y - edgeTolerance(outer.y) && inner.x + inner.width <= right + edgeTolerance(right) && inner.y + inner.height <= bottom + edgeTolerance(bottom);
|
|
70
|
+
};
|
|
71
|
+
function contentBoxOf(m, when) {
|
|
72
|
+
let box;
|
|
73
|
+
try {
|
|
74
|
+
box = m.contentBounds();
|
|
75
|
+
} catch (e) {
|
|
76
|
+
fail(`contentBounds() threw ${when}: ${String(e)}`);
|
|
77
|
+
}
|
|
78
|
+
if (box === void 0) return void 0;
|
|
79
|
+
if (!isFiniteBox(box)) {
|
|
80
|
+
fail(
|
|
81
|
+
`contentBounds() ${when} is ${describeBox(box)} \u2014 the content box must be finite with a non-negative size, or undefined when there is nothing to fit`
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
return { x: box.x, y: box.y, width: box.width, height: box.height };
|
|
85
|
+
}
|
|
86
|
+
function expectContentAroundElements(m, when) {
|
|
87
|
+
const box = contentBoxOf(m, when);
|
|
88
|
+
const listed = m.elements?.list() ?? [];
|
|
89
|
+
if (box === void 0) {
|
|
90
|
+
if (listed.length > 0) {
|
|
91
|
+
fail(
|
|
92
|
+
`contentBounds() ${when} is undefined while elements.list() reports ${listed.length} element(s) \u2014 undefined means there is nothing to fit`
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
return void 0;
|
|
96
|
+
}
|
|
97
|
+
if (m.elements && hasBounds(m.elements)) {
|
|
98
|
+
for (const { id } of listed) {
|
|
99
|
+
const element = m.elements.bounds(id);
|
|
100
|
+
if (!isFiniteBox(element)) continue;
|
|
101
|
+
if (!covers(box, element)) {
|
|
102
|
+
fail(
|
|
103
|
+
`contentBounds() ${when} is ${describeBox(box)}, which does not cover elements.bounds('${id}') = ${describeBox(element)} \u2014 the content box holds every element (and reads the live canvas)`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return box;
|
|
109
|
+
}
|
|
110
|
+
function boxesOf(elements, when) {
|
|
111
|
+
const boxes = /* @__PURE__ */ new Map();
|
|
112
|
+
for (const { id } of elements.list()) {
|
|
113
|
+
const box = elements.bounds(id);
|
|
114
|
+
if (!isFiniteBox(box)) {
|
|
115
|
+
fail(
|
|
116
|
+
`elements.bounds('${id}') ${when} is ${describeBox(box)} \u2014 every listed id must give a finite box with a non-negative size`
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
boxes.set(id, { x: box.x, y: box.y, width: box.width, height: box.height });
|
|
120
|
+
}
|
|
121
|
+
return boxes;
|
|
122
|
+
}
|
|
61
123
|
function assertFinite(state, when) {
|
|
62
124
|
const json = JSON.stringify(
|
|
63
125
|
state,
|
|
@@ -572,6 +634,97 @@ ${out}`);
|
|
|
572
634
|
}
|
|
573
635
|
}
|
|
574
636
|
},
|
|
637
|
+
{
|
|
638
|
+
name: "L5: a host's view change never commits an open interaction",
|
|
639
|
+
async run(h) {
|
|
640
|
+
if (!h.openInteraction) {
|
|
641
|
+
return skip(
|
|
642
|
+
"openInteraction is undefined \u2014 a host's view change over an open interaction (a label editor with typed input) was not verified"
|
|
643
|
+
);
|
|
644
|
+
}
|
|
645
|
+
if (h.viewState === void 0) {
|
|
646
|
+
return skip(
|
|
647
|
+
"viewState is undefined \u2014 a host's view change over an open interaction was not verified (supply a panned/zoomed state)"
|
|
648
|
+
);
|
|
649
|
+
}
|
|
650
|
+
const openInteraction = h.openInteraction;
|
|
651
|
+
const commitInteraction = h.commitInteraction;
|
|
652
|
+
const viewState = h.viewState;
|
|
653
|
+
const settle = h.settle ?? defaultSettle;
|
|
654
|
+
const first = h.canonicalTexts[0] ?? "";
|
|
655
|
+
const m = await h.create();
|
|
656
|
+
try {
|
|
657
|
+
await m.importText(first);
|
|
658
|
+
const doc = exportOrFail(m, "after importing canonicalTexts[0]");
|
|
659
|
+
const open = async () => {
|
|
660
|
+
await openInteraction(m);
|
|
661
|
+
await settle();
|
|
662
|
+
const opened2 = h.interactionState?.(m);
|
|
663
|
+
if (h.interactionState && opened2 === void 0) {
|
|
664
|
+
fail("interactionState reports no interaction after openInteraction \u2014 the case proves nothing");
|
|
665
|
+
}
|
|
666
|
+
return opened2;
|
|
667
|
+
};
|
|
668
|
+
let committed;
|
|
669
|
+
if (commitInteraction) {
|
|
670
|
+
const typed = (await open())?.text;
|
|
671
|
+
await commitInteraction(m);
|
|
672
|
+
await settle();
|
|
673
|
+
committed = exportOrFail(m, "after committing the interaction");
|
|
674
|
+
if (committed === doc || typed && !committed.includes(typed)) {
|
|
675
|
+
fail(
|
|
676
|
+
"committing the interaction openInteraction opened did not write its typed input into the export \u2014 the case proves nothing (commitInteraction must commit the way a user does, openInteraction type input the serializer writes verbatim)"
|
|
677
|
+
);
|
|
678
|
+
}
|
|
679
|
+
await importOrFail(m, first, "re-importing canonicalTexts[0] after the commit rejected");
|
|
680
|
+
}
|
|
681
|
+
const opened = await open();
|
|
682
|
+
const view = m.getViewState();
|
|
683
|
+
const { calls } = await changeEvents(h, m, () => m.setViewState(viewState));
|
|
684
|
+
if (calls > 0) {
|
|
685
|
+
fail(
|
|
686
|
+
`setViewState over an open interaction fired onContentChanged ${calls}x \u2014 the host's view change committed it (L5; if every setViewState emits, see the L5 round-trip case first)`
|
|
687
|
+
);
|
|
688
|
+
}
|
|
689
|
+
if (exportOrFail(m, "after setViewState over an open interaction") !== doc) {
|
|
690
|
+
fail(
|
|
691
|
+
"setViewState over an open interaction changed the export \u2014 the host's view change committed it (L5)"
|
|
692
|
+
);
|
|
693
|
+
}
|
|
694
|
+
if (same(m.getViewState(), view)) {
|
|
695
|
+
fail(
|
|
696
|
+
"setViewState(viewState) had no effect over an open interaction \u2014 the case proves nothing (supply a state that differs from the fitted view)"
|
|
697
|
+
);
|
|
698
|
+
}
|
|
699
|
+
const after = h.interactionState?.(m);
|
|
700
|
+
let advice;
|
|
701
|
+
if (opened !== void 0 && (after?.elementId !== opened.elementId || after?.text !== opened.text)) {
|
|
702
|
+
const input = opened.text === void 0 ? "" : ` with the input ${JSON.stringify(opened.text)}`;
|
|
703
|
+
const what = after === void 0 ? "closed it" : `left ${JSON.stringify(after)} open`;
|
|
704
|
+
advice = `an interaction on '${opened.elementId}'${input} did not survive a host's view change (setViewState ${what}) \u2014 RECOMMENDED: keep it open with its typed input, so the user's commit afterwards writes what it would have written without the view change`;
|
|
705
|
+
} else if (commitInteraction && committed !== void 0) {
|
|
706
|
+
await commitInteraction(m);
|
|
707
|
+
await settle();
|
|
708
|
+
const out = exportOrFail(m, "after committing the interaction after a view change");
|
|
709
|
+
if (out !== committed) {
|
|
710
|
+
advice = `committing an interaction after a host's view change wrote another document than committing it without one \u2014 RECOMMENDED: keep it open with its typed input across a view change (if openInteraction types different input per call, this advice is the harness's):
|
|
711
|
+
--- committed without a view change
|
|
712
|
+
${committed}
|
|
713
|
+
--- committed after setViewState
|
|
714
|
+
${out}`;
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
return {
|
|
718
|
+
...commitInteraction ? {} : {
|
|
719
|
+
skipped: "commitInteraction is undefined \u2014 that the typed input changes the document (without it the case may prove nothing) and that it still commits after the view change were not checked (pass commitInteraction to check both)"
|
|
720
|
+
},
|
|
721
|
+
...advice === void 0 ? {} : { advisories: [advice] }
|
|
722
|
+
};
|
|
723
|
+
} finally {
|
|
724
|
+
m.destroy();
|
|
725
|
+
}
|
|
726
|
+
}
|
|
727
|
+
},
|
|
575
728
|
{
|
|
576
729
|
name: "elements (when present): stable ids across re-imports and unrelated edits, reveal and selection semantics",
|
|
577
730
|
async run(h) {
|
|
@@ -751,6 +904,136 @@ ${out}`);
|
|
|
751
904
|
}
|
|
752
905
|
}
|
|
753
906
|
},
|
|
907
|
+
{
|
|
908
|
+
name: "elements.bounds (when present): a finite box in diagram coordinates for every listed id, undefined for an unknown one, live after a new element and a move",
|
|
909
|
+
async run(h) {
|
|
910
|
+
const text = h.canonicalTexts[0] ?? "";
|
|
911
|
+
const settle = h.settle ?? defaultSettle;
|
|
912
|
+
const m = await h.create();
|
|
913
|
+
let viewer;
|
|
914
|
+
try {
|
|
915
|
+
await m.importText(text);
|
|
916
|
+
const elements = m.elements;
|
|
917
|
+
if (!elements)
|
|
918
|
+
return skip("the modeler exposes no elements surface (optional) \u2014 nothing to verify");
|
|
919
|
+
if (!hasBounds(elements))
|
|
920
|
+
return skip("the modeler exposes no elements.bounds (optional) \u2014 nothing to verify");
|
|
921
|
+
boxesOf(elements, "after an import");
|
|
922
|
+
if (elements.bounds("__modeler_api_no_such_id__") !== void 0)
|
|
923
|
+
fail("elements.bounds(unknown id) must return undefined");
|
|
924
|
+
const imported = new Set(elements.list().map((e) => e.id));
|
|
925
|
+
await h.mutate(m);
|
|
926
|
+
await settle();
|
|
927
|
+
for (const { id } of elements.list().filter((e) => !imported.has(e.id))) {
|
|
928
|
+
const box = elements.bounds(id);
|
|
929
|
+
if (!isFiniteBox(box)) {
|
|
930
|
+
fail(
|
|
931
|
+
`elements.bounds('${id}') of an element created in the session is ${describeBox(box)} \u2014 bounds must read the live canvas, not the last import`
|
|
932
|
+
);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
const unverified = [];
|
|
936
|
+
if (h.moveElement) {
|
|
937
|
+
const before = boxesOf(elements, "before a move");
|
|
938
|
+
const movedId = await h.moveElement(m);
|
|
939
|
+
await settle();
|
|
940
|
+
const was = before.get(movedId);
|
|
941
|
+
if (was === void 0)
|
|
942
|
+
fail(`moveElement returned '${movedId}', an id elements.list() did not report before the move`);
|
|
943
|
+
const box = boxesOf(elements, "after a move").get(movedId);
|
|
944
|
+
if (box === void 0)
|
|
945
|
+
fail(`'${movedId}' is gone from elements.list() after moveElement moved it`);
|
|
946
|
+
if (box.x === was.x && box.y === was.y) {
|
|
947
|
+
fail(
|
|
948
|
+
`elements.bounds('${movedId}') did not follow a move made through the modeler's own commands (still ${describeBox(was)}) \u2014 bounds must read the live canvas, not the last import (or moveElement did not move the element)`
|
|
949
|
+
);
|
|
950
|
+
}
|
|
951
|
+
} else {
|
|
952
|
+
unverified.push("moveElement is undefined \u2014 that a box follows a move was not verified");
|
|
953
|
+
}
|
|
954
|
+
if (h.viewState !== void 0) {
|
|
955
|
+
const atRest = boxesOf(elements, "before a view change");
|
|
956
|
+
m.setViewState(h.viewState);
|
|
957
|
+
for (const [id, box] of boxesOf(elements, "after setViewState")) {
|
|
958
|
+
if (!same(box, atRest.get(id))) {
|
|
959
|
+
fail(
|
|
960
|
+
`elements.bounds('${id}') changed with the view (${describeBox(atRest.get(id))} \u2192 ${describeBox(box)}) \u2014 boxes are in diagram coordinates, which zoom and scroll leave alone`
|
|
961
|
+
);
|
|
962
|
+
}
|
|
963
|
+
}
|
|
964
|
+
} else {
|
|
965
|
+
unverified.push(
|
|
966
|
+
"viewState is undefined \u2014 that boxes are independent of the view was not verified"
|
|
967
|
+
);
|
|
968
|
+
}
|
|
969
|
+
if (h.createReadonly) {
|
|
970
|
+
viewer = await h.createReadonly();
|
|
971
|
+
await importOrFail(viewer, text, "the viewer rejected canonicalTexts[0]");
|
|
972
|
+
if (viewer.elements && hasBounds(viewer.elements)) {
|
|
973
|
+
boxesOf(viewer.elements, "on the viewer after an import");
|
|
974
|
+
if (viewer.elements.bounds("__modeler_api_no_such_id__") !== void 0)
|
|
975
|
+
fail("the viewer's elements.bounds(unknown id) must return undefined");
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
if (unverified.length > 0) return skip(unverified.join("; "));
|
|
979
|
+
} finally {
|
|
980
|
+
m.destroy();
|
|
981
|
+
viewer?.destroy();
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
},
|
|
985
|
+
{
|
|
986
|
+
name: "contentBounds (when present): a finite box in diagram coordinates around every listed element, live after a new element, unchanged by zoom and scroll",
|
|
987
|
+
async run(h) {
|
|
988
|
+
const settle = h.settle ?? defaultSettle;
|
|
989
|
+
const m = await h.create();
|
|
990
|
+
let viewer;
|
|
991
|
+
try {
|
|
992
|
+
if (!hasContentBounds(m))
|
|
993
|
+
return skip("the modeler exposes no contentBounds (optional, 1.3) \u2014 nothing to verify");
|
|
994
|
+
contentBoxOf(m, "before the first import");
|
|
995
|
+
for (const [index, text] of h.canonicalTexts.entries()) {
|
|
996
|
+
await importOrFail(m, text, `importText(canonicalTexts[${index}]) rejected`);
|
|
997
|
+
expectContentAroundElements(m, `after importing canonicalTexts[${index}]`);
|
|
998
|
+
}
|
|
999
|
+
await importOrFail(m, h.canonicalTexts[0] ?? "", "importText(canonicalTexts[0]) rejected");
|
|
1000
|
+
await h.mutate(m);
|
|
1001
|
+
await settle();
|
|
1002
|
+
const atRest = expectContentAroundElements(m, "after a user mutation added an element");
|
|
1003
|
+
const unverified = [];
|
|
1004
|
+
if (h.viewState !== void 0) {
|
|
1005
|
+
m.setViewState(h.viewState);
|
|
1006
|
+
const viewed = contentBoxOf(m, "after setViewState");
|
|
1007
|
+
if (!same(viewed, atRest)) {
|
|
1008
|
+
fail(
|
|
1009
|
+
`contentBounds() changed with the view (${describeBox(atRest)} \u2192 ${describeBox(viewed)}) \u2014 the content box is in diagram coordinates, which zoom and scroll leave alone`
|
|
1010
|
+
);
|
|
1011
|
+
}
|
|
1012
|
+
} else {
|
|
1013
|
+
unverified.push(
|
|
1014
|
+
"viewState is undefined \u2014 that the content box is independent of the view was not verified"
|
|
1015
|
+
);
|
|
1016
|
+
}
|
|
1017
|
+
if (!m.elements || !hasBounds(m.elements)) {
|
|
1018
|
+
unverified.push(
|
|
1019
|
+
"the modeler exposes no elements.bounds \u2014 that the content box covers every element was not verified"
|
|
1020
|
+
);
|
|
1021
|
+
}
|
|
1022
|
+
if (h.createReadonly) {
|
|
1023
|
+
viewer = await h.createReadonly();
|
|
1024
|
+
if (hasContentBounds(viewer)) {
|
|
1025
|
+
contentBoxOf(viewer, "on the viewer before the first import");
|
|
1026
|
+
await importOrFail(viewer, h.canonicalTexts[0] ?? "", "the viewer rejected canonicalTexts[0]");
|
|
1027
|
+
expectContentAroundElements(viewer, "on the viewer after an import");
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
if (unverified.length > 0) return skip(unverified.join("; "));
|
|
1031
|
+
} finally {
|
|
1032
|
+
m.destroy();
|
|
1033
|
+
viewer?.destroy();
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
},
|
|
754
1037
|
{
|
|
755
1038
|
name: "L6: export is total after imports, user mutations and undo",
|
|
756
1039
|
async run(h) {
|