@weasel-js/diagram 1.15.0 → 1.15.1

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.
Files changed (34) hide show
  1. package/README.md +114 -5
  2. package/dist/{chunk-GR2DK4S2.js → chunk-EIHPPOAM.js} +1480 -229
  3. package/dist/chunk-EIHPPOAM.js.map +1 -0
  4. package/dist/{chunk-AXL4JQBM.js → chunk-EIT4BFDK.js} +3 -3
  5. package/dist/{chunk-AXL4JQBM.js.map → chunk-EIT4BFDK.js.map} +1 -1
  6. package/dist/{chunk-DE7UILJA.js → chunk-NEX4QKQQ.js} +183 -23
  7. package/dist/chunk-NEX4QKQQ.js.map +1 -0
  8. package/dist/{chunk-FDCODMFW.js → chunk-UOFQBGJY.js} +904 -599
  9. package/dist/chunk-UOFQBGJY.js.map +1 -0
  10. package/dist/{chunk-IYUU5KUY.js → chunk-UUMLQEMR.js} +8 -96
  11. package/dist/chunk-UUMLQEMR.js.map +1 -0
  12. package/dist/{dataTypes-BIkhAOc4.d.ts → dataTypes-1ch6cMtq.d.ts} +12 -3
  13. package/dist/effect-audio.d.ts +2 -2
  14. package/dist/effect-audio.js +3 -3
  15. package/dist/effect.d.ts +5 -5
  16. package/dist/effect.js +7 -7
  17. package/dist/effect.js.map +1 -1
  18. package/dist/icons.table.js +44 -0
  19. package/dist/icons.table.js.map +1 -1
  20. package/dist/icons.table.json +44 -0
  21. package/dist/index.d.ts +938 -37
  22. package/dist/index.js +708 -34
  23. package/dist/index.js.map +1 -1
  24. package/dist/{labelTrait-BBjRgxbz.d.ts → labelTrait-moIciyXr.d.ts} +4 -0
  25. package/dist/layout.d.ts +3 -3
  26. package/dist/{layout.entry-CbmGuqE-.d.ts → layout.entry-zstuljAl.d.ts} +2 -2
  27. package/dist/layout.js +2 -2
  28. package/dist/{stageTypes-UiO25hcn.d.ts → stageTypes-B7oF8Lww.d.ts} +1 -1
  29. package/dist/{types-B0n2CNTW.d.ts → types-D5ybp8Xh.d.ts} +32 -1
  30. package/package.json +11 -11
  31. package/dist/chunk-DE7UILJA.js.map +0 -1
  32. package/dist/chunk-FDCODMFW.js.map +0 -1
  33. package/dist/chunk-GR2DK4S2.js.map +0 -1
  34. package/dist/chunk-IYUU5KUY.js.map +0 -1
package/README.md CHANGED
@@ -265,6 +265,11 @@ const spec = edgeLabelSpec(edgeId, 'yes', { layer: 'diagram' });
265
265
  `labelSize` is the box a label's text takes. Both routes size with it, so a
266
266
  label built from data and one the action creates come out the same size.
267
267
 
268
+ A label's `at` is `'start'`, `'mid'`, `'end'`, a fraction of the route, or
269
+ `{ near }` a point. At `'start'` or `'end'`, `inset` stands the label's near
270
+ side that far along the route from the end, so it clears the shape the route
271
+ meets; that is how an edge's `endLabels` sit.
272
+
268
273
  ### Labels that dodge
269
274
 
270
275
  After any edit, a label that would sit on a shape, on another label, or across
@@ -522,6 +527,29 @@ useDepSource('canDropInto', () => diagramCanDropInto(scene));
522
527
  const containers = useMemo(() => diagramContainers({ scene, selected }), [scene, selected]);
523
528
  ```
524
529
 
530
+ ### Diagram types
531
+
532
+ A `DiagramType` is a kind of diagram: the stencil groups (`STENCIL_GROUPS`) its Shapes panel opens with, how a new
533
+ connector starts (`edge`: router, end markers, dash), the layout Auto layout runs, and the `notations` its graph
534
+ pages are written in. `DIAGRAM_TYPES` ships these:
535
+
536
+ | Type | Groups | Notation |
537
+ | --- | --- | --- |
538
+ | Flowchart | flowchart, containers | `FLOWCHART_NOTATION` |
539
+ | Org chart, Network, BPMN | their own, containers | none: written as a flowchart |
540
+ | UML class, Entity relationship, Mind map | their own (UML adds containers) | `class`, `er`, `mindmap` |
541
+ | State | state: states, start, end, choice, fork or join, note, composite and concurrent states | `state` |
542
+ | Requirement | requirement: requirements and elements, joined dashed | `requirement` |
543
+ | C4 | C4: people, systems, containers, components, stores, queues, boundaries | `c4-context`, and the other levels on import |
544
+ | Block | flowchart, containers, laid out on a grid | `block` |
545
+ | Architecture | architecture: services by Mermaid's built-in icons, junctions, groups | `architecture` |
546
+ | Kanban | kanban: a board of column lanes, cards | `kanban` |
547
+
548
+ The type a scene holds is its `diagram:type` document value (`diagramTypeOf`, `setDiagramType`), and
549
+ `diagramNotationOf(scene)` the notation a page of it is written in. A stencil's `themeRole` puts that theme role on
550
+ the body it draws, as C4's outside elements are `muted`; `useStencilInsert` resolves its colors when given `theme`.
551
+ A container stencil may name its `title` and the `lanes` a pool starts with.
552
+
525
553
  The layouts register by key through `withDiagramRegistry`, so a saved scene
526
554
  finds them again: `diagram:container`, `diagram:pool-rows`,
527
555
  `diagram:pool-columns`, `diagram:lane-rows`, and `diagram:lane-columns`.
@@ -586,7 +614,7 @@ dragged undoes in one step; `scene.history.seal()` ends the run. `parseDiagramTh
586
614
 
587
615
  ### Laying it out
588
616
 
589
- `layered`, `tree`, `force`, `chain`, and `radial` are plain functions of the graph. Each
617
+ `layered`, `tree`, `force`, `chain`, `radial`, and `grid` are plain functions of the graph. Each
590
618
  hands back the new top-left for every node that **moves** — a node already
591
619
  standing where the layout wants it is absent, so re-running a layout on an
592
620
  unchanged diagram writes nothing at all.
@@ -680,6 +708,16 @@ sides are dealt in graph order and each side keeps the order its branches stand
680
708
  moves nothing. Further trees lay out the same way, stacked below the first. `direction` and groups
681
709
  are ignored.
682
710
 
711
+ `grid` stands nodes in rows of a fixed number of columns, left to right and top to bottom, as a
712
+ block diagram does. Its `grid` option gives the top level's `columns` (unset, everything in one
713
+ row), each group's own under `groupColumns`, how many columns an item `spans`, and how many empty
714
+ cells it `skips` before it, all by id. Items fill their cells in graph order, a group where its
715
+ first member would stand. Every column of one grid is as wide as its widest item needs, a spanning
716
+ item sharing its width over its columns, and every row as tall as its tallest item; an item is
717
+ centered in its cells. A group (or a container fitted to what it holds) is a grid of its own in
718
+ its cells, its inset kept around it. Columns are `nodeGap` apart and rows `rankGap`, or `nodeGap`
719
+ when `rankGap` is unset. Edges and `direction` are ignored, so a second run moves nothing.
720
+
683
721
  ### From data
684
722
 
685
723
  `diagramScene` turns plain `{ nodes, edges }` into a laid-out scene, and
@@ -702,7 +740,10 @@ label row each. A `slot` row is reserved space, `height` tall and, with a
702
740
  `width`, that wide and centered; one with an `id` becomes a scene node of that
703
741
  name, `<node>/<id>`, drawn as an empty frame until you fill it by changing its
704
742
  data — with `{ image: { src } }`, say. An edge can name `fromPort`/`toPort`, its own `router`,
705
- `waypoints`, `labelPlacement`, and a theme role in `style`.
743
+ `waypoints`, `labelPlacement`, and a theme role in `style`. Its `endLabels`
744
+ `{ from, to }` draw text beside each end, a multiplicity or a role, as labels at
745
+ `'start'` and `'end'` (`END_LABEL_PLACEMENT`) whose ids `endLabelIdOf(edge, end)`
746
+ gives.
706
747
 
707
748
  A node, an edge, a container, or a lane can carry `colors` of its own: a node's `fill`, `stroke`,
708
749
  and `text`, an edge's `stroke`, `label`, `width`, `dash`, and markers. `diagramScene` draws them
@@ -718,15 +759,20 @@ over the box, so it follows its node as marks do. The built-in names are the
718
759
  flowchart shapes `'rect'`, `'diamond'`, `'stadium'`, `'ellipse'`, `'parallelogram'`,
719
760
  `'trapezoid'` (a demultiplexer: tall at the right, short at the left), and
720
761
  `'hexagon'` (pointed at the left and right, its rows kept between the points);
721
- `'roundRect'`, `'triangle'`, `'octagon'`, `'cloud'`, `'doubleEllipse'`, and
722
- `'actor'` (a stick figure, its label in the strip beneath it); and `'cylinder'`,
762
+ `'roundRect'`, `'triangle'`, `'octagon'`, `'cloud'`, `'doubleEllipse'`,
763
+ `'actor'` (a stick figure, its label in the strip beneath it), and `'person'` (a head over a body
764
+ with rounded shoulders, its rows in the body); and `'cylinder'`,
723
765
  `'document'`, `'note'`, `'folder'`, and `'cube'`. Each keeps its rows inside the
724
766
  visible shape, clear of a cylinder's cap or a note's fold. Some draw a detail,
725
767
  stroked over the fill: a cylinder's rim, a note's fold, a cube's front edges.
768
+ The state-machine figures `'start'` (a filled dot), `'end'` (a ring around a
769
+ dot), and `'bar'` (a fork or join, 6 thick along the box's longer side) keep
770
+ their proportions centered in any box, and fill their solid part in the
771
+ stroke's color.
726
772
 
727
773
  `registerOutline(name, def)` adds a name, or shadows a built-in until its
728
774
  disposer runs. An `OutlineDef` builds `path` in a node's bounds, and optionally
729
- `detail`, `content` (the box rows lay out in), and `boxForContent` (its inverse,
775
+ `detail`, `solid` (filled in the stroke's color over the fill), `content` (the box rows lay out in), and `boxForContent` (its inverse,
730
776
  for sizing a node to its rows). `outlineFromD(d, { detail, content })` builds one
731
777
  from SVG path data in a unit square. A saved name that is not registered paints
732
778
  as `'rect'` and warns once.
@@ -919,6 +965,69 @@ blank. The view opens fitted to the diagram and fits again when `width` or
919
965
  `height` changes or a layout run settles, until the user pans or zooms. `minScale` stops the fit from
920
966
  shrinking a wide diagram past readable; the rest is a pan away.
921
967
 
968
+ ### Sequence diagrams
969
+
970
+ A `SequenceData` is participants left to right and steps top to bottom:
971
+ messages, notes, activations, `create` and `destroy`, and fragments (`loop`,
972
+ `alt`, `opt`, `par`, `critical`, `break`, and a colored `region`) holding runs
973
+ of steps in sections. `boxes` draw around participants' columns, and
974
+ `autonumber` numbers the messages from a start.
975
+
976
+ ```tsx
977
+ const data: SequenceData = {
978
+ participants: [{ id: 'a', label: 'Alice', outline: 'actor' }, { id: 'b', label: 'Bob' }],
979
+ steps: [
980
+ { kind: 'message', id: 'm1', from: 'a', to: 'b', text: 'Hello', line: 'solid', head: 'arrow', activate: 'to' },
981
+ { kind: 'message', id: 'm2', from: 'b', to: 'a', text: 'Hi', line: 'dashed', head: 'arrow', deactivate: 'from' },
982
+ ],
983
+ };
984
+ const [seq, setSeq] = useState(data);
985
+ const specs = useMemo(() => sequenceSpecs(seq, { id: 'hello' }), [seq]);
986
+ <DiagramView specs={specs} onEditSequence={(edit) => setSeq(edit.data)} />;
987
+ ```
988
+
989
+ `sequenceSpecs(data, { id, at, theme, measure })` lays the data out
990
+ (`sequenceLayout` gives the geometry alone): lifelines spaced so the widest
991
+ text between neighbors fits, a row per step sized to its text, self-messages
992
+ looped, a head started at its `create` and a lifeline ended at its `destroy`,
993
+ nested activations stepped right, and each fragment boxed over the lifelines
994
+ its steps touch, with its type in a tab and a dashed line between sections. It
995
+ returns one root node, `id`, holding the data, and every part as a child of it
996
+ that takes no press. Heads wear the participant's outline: `actor`, `boundary`,
997
+ `control`, `entity`, `cylinder` for a database, `collections`, and `queue`
998
+ besides any other. Every part is drawn in the theme: a head and its
999
+ activations in the participant's role, a message in the connector style, a
1000
+ note in `SEQUENCE_ROLES.note`, a fragment or a box as a container.
1001
+
1002
+ The edits are pure functions of the data: `moveStep` (into or out of a
1003
+ fragment's section), `moveParticipant`, `reconnectMessage`, and
1004
+ `setSequenceText`. `DiagramView`'s `onEditSequence` turns them on as drags — a
1005
+ message or note to another row, a head sideways, a message end onto another
1006
+ lifeline — and double-click text editing, each reported as the sequence's new
1007
+ data. On a scene that is the document, `diagramSequence({ scene, measure })`
1008
+ gives the layer and contribution that commit each edit as one undo entry
1009
+ (`commitSequence`), and `foldSequenceText` turns a text edit on a part into one
1010
+ edit of the data. A theme applied with `applyDiagramTheme` draws every sequence
1011
+ again.
1012
+
1013
+ A sequence is built from nothing with more pure edits: `addParticipant` and
1014
+ `removeParticipant` (which takes every message, mark, and note naming it),
1015
+ `insertMessage` with an arrow from `SEQ_ARROWS`, `insertNote`, `insertMark` for
1016
+ activations, creations, and destructions, `wrapSteps` to put a run of steps in
1017
+ a fragment and `addSection` for an alt's next branch, `removeStep`, `addBox`, and
1018
+ `setAutonumber`, among others. `useSequenceTools` builds the tools in
1019
+ `SEQUENCE_TOOLS` that make them on the canvas: Participant clicks a lifeline in
1020
+ between two (or starts a sequence on empty canvas), Message drags from one
1021
+ lifeline to another, Note clicks or drags across lifelines, and Fragment drags
1022
+ across rows, and Mark clicks an activation's start or end, a creation, or a
1023
+ destruction onto a lifeline. Pass them as `tools` to `DiagramView` or
1024
+ `<SceneCanvas>`. `sequenceSelectionOf(scene, ids)` reads a selection as one
1025
+ sequence's participants, messages, notes, fragments, and boxes, for a panel
1026
+ that offers the edits fitting it. A click
1027
+ on a sequence's part selects it, and `createSequenceDeleteAction` (which
1028
+ `DiagramView` installs with `onEditSequence`) makes Delete remove it from the
1029
+ data.
1030
+
922
1031
  ### Effect charts
923
1032
 
924
1033
  `@weasel-js/diagram/effect` draws an effects pipeline: the stages a signal