@nice2dev/ui-diagrams 1.4.14 → 1.4.15

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/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # @nice2dev/ui-diagrams — Changelog
2
2
 
3
+ ## 1.4.15
4
+
5
+ ### Patch Changes
6
+
7
+ - 8f06640: OmniVerk wishlist 1.4.0, diagrams:
8
+
9
+ - **#5 Export.** One scene now backs every format. Edges run as on the canvas: the geometry moved to
10
+ the new exported `diagramEdgeShape` and `diagramPortPoint`.
11
+ - `exportToSvg` draws the canvas's lines and shapes (it drew centre-to-centre lines).
12
+ - New `exportToPng` draws a real PNG; PNG previously went out as SVG text.
13
+ - New `exportToPdf` / `sceneToPdf` write a vector PDF with no dependencies.
14
+ - Paths and Helvetica text, so the PDF stays sharp and its text can be selected.
15
+ - Polish and other Latin letters are text; a label in another script is an image in a browser.
16
+ - One fitted page, or tiles over several pages; A4, A3 or Letter, either orientation.
17
+ - Both return a promise; the PDF writer loads on the first PDF export, so the editor does not carry it.
18
+ - Also new: `diagramScene` and `sceneToSvg`.
19
+ - `NiceDiagramEditor`:
20
+ - takes a `ref` with `export(format)`;
21
+ - has PDF in the toolbar;
22
+ - sends PNG and PDF to the new `onExportFile`, or downloads them;
23
+ - adds an export row in `readOnly` with `showExportInReadOnly`.
24
+ - `DiagramToolbar`'s `onExport` format adds `'pdf'`.
25
+ - **#7 Tidy tree.** `autoLayout` `'tree'` is a tidy tree; it used to be the layered layout.
26
+ - Children keep their edge order and a parent stands over the middle of its children.
27
+ - Branches never overlap.
28
+ - `diagramType` now works (it was ignored): `'orgchart'` with `autoLayout` lays out top-down as a
29
+ tree and draws square-cornered connectors from parent bottom to child top.
30
+ - New `tidyTreeLayout` in `@nice2dev/ui`.
31
+ - **#8 `NiceOrganizationChart`.**
32
+ - A chart wider than its box starts at the left edge and scrolls; centring used to cut off the
33
+ left part.
34
+ - Sibling connectors no longer have gaps.
35
+ - New `zoomable` (zoom out / in, fit), and `exportable` / `onExport` for SVG and PNG drawn from the
36
+ data.
37
+ - New `orgChartToSvg` / `orgChartToPng`.
38
+
3
39
  ## 1.4.14
4
40
 
5
41
  No changes in this release.
@@ -3,6 +3,11 @@ import { AnimationState } from '../core/animationEngine';
3
3
  import { ParticleEngineState } from '../core/diagramParticleEngine';
4
4
  import { DiagramNode, DiagramEdge, DiagramGroup, DiagramViewport, DiagramThemeOverrides, DiagramViewMode, Point, Size } from '../types/diagramTypes';
5
5
  export interface DiagramCanvasProps {
6
+ /**
7
+ * Tree connectors (1.4.15, org charts): edges drawn as the default bezier run from the parent's
8
+ * bottom middle into the child's top middle, square-cornered.
9
+ */
10
+ treeEdges?: boolean;
6
11
  nodes: readonly DiagramNode[];
7
12
  edges: readonly DiagramEdge[];
8
13
  groups?: readonly DiagramGroup[];
@@ -14,7 +14,7 @@ export interface DiagramToolbarProps {
14
14
  onRedo?: () => void;
15
15
  canUndo?: boolean;
16
16
  canRedo?: boolean;
17
- onExport?: (format: 'svg' | 'mermaid' | 'ndd' | 'png') => void;
17
+ onExport?: (format: 'svg' | 'mermaid' | 'ndd' | 'png' | 'pdf') => void;
18
18
  onZoomIn?: () => void;
19
19
  onZoomOut?: () => void;
20
20
  onZoomReset?: () => void;
@@ -30,8 +30,15 @@ export interface NiceDiagramEditorProps {
30
30
  diagramType?: DiagramType;
31
31
  /** Fires on every document change */
32
32
  onChange?: (doc: Readonly<NiceDiagramDocument>) => void;
33
- /** Export callback (called when user exports via toolbar) */
33
+ /** Export callback (called when user exports via toolbar): the text formats — SVG, Mermaid, .ndd.json. */
34
34
  onExport?: (format: string, content: string) => void;
35
+ /**
36
+ * The file formats exported from the toolbar (1.4.15): PNG and a vector PDF. Without it the file
37
+ * downloads. (PNG went to `onExport` as SVG text before.)
38
+ */
39
+ onExportFile?: (format: 'png' | 'pdf', file: Blob) => void;
40
+ /** An export button in `readOnly` too (1.4.15; `ref.export(format)` works either way). */
41
+ showExportInReadOnly?: boolean;
35
42
  /**
36
43
  * Language of the editor's own texts. Default: the app's (its global NiceI18nProvider) — it
37
44
  * was English whatever the app used, before 1.3.17.
@@ -52,4 +59,9 @@ export interface NiceDiagramEditorProps {
52
59
  /** Optional "?" guided tour. Off by default; `true` uses the built-in tour. */
53
60
  tutorial?: NiceComponentTutorial;
54
61
  }
55
- export declare const NiceDiagramEditor: React.FC<NiceDiagramEditorProps>;
62
+ /** What a `ref` on NiceDiagramEditor gives (1.4.15 — OmniVerk wishlist #5): the diagram exported. */
63
+ export interface NiceDiagramEditorHandle {
64
+ /** The diagram in a format: text for SVG, Mermaid and .ndd.json, a file for PNG and PDF. */
65
+ export(format: 'svg' | 'mermaid' | 'ndd' | 'png' | 'pdf'): Promise<string | Blob>;
66
+ }
67
+ export declare const NiceDiagramEditor: React.ForwardRefExoticComponent<NiceDiagramEditorProps & React.RefAttributes<NiceDiagramEditorHandle>>;
@@ -0,0 +1,23 @@
1
+ import { DiagramEdge, DiagramNode, Point } from '../types/diagramTypes';
2
+ /** An edge's path (`M` / `L` / `C` commands), its label's point, and points bounding what it draws. */
3
+ export interface DiagramEdgeShape {
4
+ d: string;
5
+ mid: Point;
6
+ extent: Point[];
7
+ }
8
+ export interface DiagramEdgeShapeOptions {
9
+ /**
10
+ * Tree connectors (1.4.15, org charts): an edge drawn as the default bezier runs from its parent's
11
+ * bottom middle down, across and down into its child's top middle — whatever ports it names.
12
+ */
13
+ treeEdges?: boolean;
14
+ }
15
+ /** A port's point on its node's boundary (the node's centre for a missing port). */
16
+ export declare function diagramPortPoint(nodes: readonly DiagramNode[], nodeId: string, portId: string): Point;
17
+ /**
18
+ * An edge's path, the point its label goes to, and points that bound what it draws (for a fit).
19
+ * 1.3.17: a bezier leaves and enters along each port's side (down from a bottom port, left into a
20
+ * left one) — before it always ran horizontally, so edges between top / bottom ports and back
21
+ * edges looped through the nodes.
22
+ */
23
+ export declare function diagramEdgeShape(edge: DiagramEdge, nodes: readonly DiagramNode[], options?: DiagramEdgeShapeOptions): DiagramEdgeShape;
@@ -1,8 +1,68 @@
1
1
  import { NiceDiagramDocument, DiagramExportOptions } from '../types/diagramTypes';
2
+ import { DiagramPdfOptions } from './pdfWriter';
3
+ /** One thing a scene draws. Paths use only `M`, `L`, `C` and `Z`. */
4
+ export type DiagramSceneItem = {
5
+ kind: 'path';
6
+ d: string;
7
+ fill?: string;
8
+ stroke?: string;
9
+ strokeWidth?: number;
10
+ dash?: number[];
11
+ } | {
12
+ kind: 'text';
13
+ /** The text's anchor point: its middle (or start) at the baseline's height. */
14
+ x: number;
15
+ y: number;
16
+ text: string;
17
+ size: number;
18
+ color: string;
19
+ anchor: 'middle' | 'start';
20
+ };
21
+ /** A diagram as drawing instructions, in its own units, starting at (0, 0). */
22
+ export interface DiagramScene {
23
+ width: number;
24
+ height: number;
25
+ background?: string;
26
+ items: DiagramSceneItem[];
27
+ }
28
+ export interface DiagramSceneOptions {
29
+ /** Room around the drawing (40). */
30
+ padding?: number;
31
+ /** A background colour (none: transparent). */
32
+ background?: string;
33
+ /** Org-chart connectors for edges without their own line type (as the editor draws them). */
34
+ treeEdges?: boolean;
35
+ }
36
+ /** The drawing of a diagram: its nodes, edges, arrowheads and labels, padded, from (0, 0). */
37
+ export declare function diagramScene(doc: NiceDiagramDocument, options?: DiagramSceneOptions): DiagramScene;
38
+ /** A scene as an SVG document. */
39
+ export declare function sceneToSvg(scene: DiagramScene, scale?: number): string;
2
40
  /**
3
- * Export diagram to SVG string.
41
+ * Export diagram to SVG string — the same lines and shapes as the canvas (1.4.15; it drew every
42
+ * edge as a centre-to-centre line).
4
43
  */
5
- export declare function exportToSvg(doc: NiceDiagramDocument, options?: Partial<DiagramExportOptions>): string;
44
+ export declare function exportToSvg(doc: NiceDiagramDocument, options?: Partial<DiagramExportOptions> & {
45
+ treeEdges?: boolean;
46
+ }): string;
47
+ /** Export a diagram as a PNG image (1.4.15; in a browser — the SVG drawn to a canvas). */
48
+ export declare function exportToPng(doc: NiceDiagramDocument, options?: {
49
+ scale?: number;
50
+ background?: string;
51
+ treeEdges?: boolean;
52
+ }): Promise<Blob>;
53
+ export type { DiagramPdfOptions } from './pdfWriter';
54
+ /**
55
+ * A scene as a vector PDF: its paths and text (Helvetica), on one page or tiled. The writer loads on
56
+ * first use.
57
+ */
58
+ export declare function sceneToPdf(scene: DiagramScene, options?: DiagramPdfOptions): Promise<Uint8Array>;
59
+ /**
60
+ * Export a diagram as a vector PDF (1.4.15, OmniVerk wishlist #5): the same drawing as the SVG
61
+ * export — paths and Helvetica text, so it stays sharp at any zoom and its text can be selected —
62
+ * fitted on one page or tiled over several. Latin text (Polish and other European letters
63
+ * included) is text; a label in another script is drawn as an image in a browser.
64
+ */
65
+ export declare function exportToPdf(doc: NiceDiagramDocument, options?: DiagramPdfOptions): Promise<Blob>;
6
66
  /**
7
67
  * Export diagram to Mermaid syntax string.
8
68
  */
@@ -0,0 +1,19 @@
1
+ import { DiagramScene } from './exportEngine';
2
+ /** A path's commands as [command, numbers][] (M, L, C, Z) — exportEngine's parser, passed in. */
3
+ export type DiagramPathCommands = (d: string) => Array<[string, number[]]>;
4
+ export interface DiagramPdfOptions {
5
+ /** Paper (default A4). */
6
+ pageSize?: 'A4' | 'A3' | 'Letter';
7
+ /** `auto` (default) turns the page to the diagram's longer side. */
8
+ orientation?: 'auto' | 'portrait' | 'landscape';
9
+ /** The whole diagram fitted on one page (default), or at full size over as many pages as it takes. */
10
+ layout?: 'fit' | 'tiles';
11
+ /** Page margin in points (28). */
12
+ margin?: number;
13
+ background?: string;
14
+ treeEdges?: boolean;
15
+ /** PDF title. */
16
+ title?: string;
17
+ }
18
+ /** A diagram as a vector PDF: its paths and text (Helvetica), on one page or tiled. */
19
+ export declare function writeDiagramPdf(scene: DiagramScene, options: DiagramPdfOptions, pathCommands: DiagramPathCommands): Uint8Array;