@visuallyjs/browser-ui-svelte 1.2.3 → 1.2.5

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.
@@ -1,9 +1,7 @@
1
1
  <script lang="ts">
2
2
 
3
3
  import {type DiagramPaletteProps} from "./definitions";
4
- import {Diagram, DiagramPalette, log} from "@visuallyjs/browser-ui";
5
- import {internal_getDiagramContext} from "./diagram-store";
6
- import {onMount} from "svelte";
4
+ import {DiagramPalette} from "@visuallyjs/browser-ui";
7
5
  import {useDiagram} from "./use-diagram.svelte";
8
6
 
9
7
  let initialised = false
@@ -30,7 +28,13 @@
30
28
  autoExitDrawMode:props.autoExitDrawMode,
31
29
  selectAfterAdd:props.selectAfterAdd,
32
30
  onVertexAdded:props.onVertexAdded,
33
- preparedShapes:props.preparedShapes
31
+ preparedShapes:props.preparedShapes,
32
+ allowDropOnEdge:props.allowDropOnEdge,
33
+ allowRotation:props.allowRotation,
34
+ rotationSpeed:props.rotationSpeed,
35
+ autoEdgeConnect:props.autoEdgeConnect,
36
+ showGroups:props.showGroups !== false,
37
+ updateTypeOnPaletteTap:props.updateTypeOnPaletteTap
34
38
  })
35
39
  }
36
40
  })
@@ -27,7 +27,10 @@
27
27
  allowDropOnGroup = true,
28
28
  allowDropOnCanvas = true,
29
29
  allowDropOnNode = false,
30
- ignoreDropOnNode = false
30
+ ignoreDropOnNode = false,
31
+ allowRotation = true,
32
+ rotationSpeed = 2000,
33
+ autoEdgeConnect = false
31
34
  }:PaletteComponentProps = $props()
32
35
 
33
36
  $effect(() => {
@@ -48,7 +51,13 @@
48
51
  allowDropOnEdge,
49
52
  allowDropOnCanvas,
50
53
  allowDropOnGroup,
51
- ignoreDropOnNode
54
+ ignoreDropOnNode,
55
+ allowRotation,
56
+ rotationSpeed,
57
+ autoEdgeConnect,
58
+ autoEdgeConnectActiveClass,
59
+ autoEdgeConnectMode,
60
+ autoEdgeLineStyle
52
61
  })
53
62
  }
54
63
 
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { onMount, type Snippet } from "svelte";
2
+ import { onMount, untrack, type Snippet } from "svelte";
3
3
  import {
4
4
  BrowserUISvelteModel,
5
5
  newInstance,
@@ -47,6 +47,7 @@
47
47
  model,
48
48
  data,
49
49
  url,
50
+ dataType,
50
51
  shapeLibrary,
51
52
  injector,
52
53
  children
@@ -54,7 +55,7 @@
54
55
 
55
56
  const paperContext = internal_getPaperContext(false);
56
57
 
57
- let paper:Paper;
58
+ let paper = $state<Paper>();
58
59
 
59
60
  export function getPaper() {
60
61
  return paper
@@ -200,6 +201,30 @@
200
201
  el.parentNode && el.parentNode.removeChild(el);
201
202
  }
202
203
 
204
+ $effect(() => {
205
+ if (url != null && paper != null) {
206
+ untrack(() => {
207
+ paper.model.clear();
208
+ requestAnimationFrame(() => {
209
+ paper.model.load({ url, dataType });
210
+ })
211
+
212
+ });
213
+ }
214
+ });
215
+
216
+ $effect(() => {
217
+ if (data != null && paper != null) {
218
+ untrack(() => {
219
+ paper.model.clear();
220
+ requestAnimationFrame(() => {
221
+ paper.model.load({ data, dataType });
222
+ })
223
+
224
+ });
225
+ }
226
+ });
227
+
203
228
  onMount(async () => {
204
229
  model = model || newInstance(modelOptions || {});
205
230
 
@@ -335,12 +360,6 @@
335
360
  _overlays = []
336
361
  _updateOverlayState()
337
362
  })
338
-
339
- if (url != null) {
340
- model.load({ url });
341
- } else if (data != null) {
342
- model.load({ data });
343
- }
344
363
  });
345
364
 
346
365
  </script>
@@ -22,7 +22,13 @@
22
22
  allowClickToAdd,
23
23
  autoExitDrawMode,
24
24
  inspector = true,
25
- preparedShapes
25
+ updateTypeOnPaletteTap = false,
26
+ preparedShapes,
27
+ allowDropOnEdge,
28
+ allowRotation = true,
29
+ rotationSpeed = 2000,
30
+ autoEdgeConnect,
31
+ showGroups = true
26
32
  }:ShapePaletteComponentProps = $props()
27
33
 
28
34
  let container:HTMLElement
@@ -57,8 +63,13 @@
57
63
  fill,
58
64
  dragSize,
59
65
  inspector,
60
- preparedShapes
61
-
66
+ updateTypeOnPaletteTap,
67
+ preparedShapes,
68
+ allowDropOnEdge,
69
+ allowRotation,
70
+ rotationSpeed,
71
+ autoEdgeConnect,
72
+ showGroups
62
73
  })
63
74
 
64
75
  }
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import { onMount, type Snippet } from "svelte";
2
+ import {onMount, type Snippet, untrack} from "svelte";
3
3
  import {
4
4
  BrowserUISvelteModel, internal_createDiagramContext,
5
5
  newInstance,
@@ -47,6 +47,7 @@
47
47
  model,
48
48
  data,
49
49
  url,
50
+ dataType,
50
51
  shapeLibrary,
51
52
  injector,
52
53
  children
@@ -54,7 +55,7 @@
54
55
 
55
56
  const surfaceContext = internal_getSurfaceContext(false);
56
57
 
57
- let surface:Surface;
58
+ let surface = $state<Surface>();
58
59
 
59
60
  export function getSurface() {
60
61
  return surface
@@ -200,6 +201,28 @@
200
201
  el.parentNode && el.parentNode.removeChild(el);
201
202
  }
202
203
 
204
+ $effect(() => {
205
+ if (url != null && surface != null) {
206
+ untrack(() => {
207
+ surface.model.clear();
208
+ requestAnimationFrame(() => {
209
+ surface.model.load({url, dataType});
210
+ })
211
+ });
212
+ }
213
+ });
214
+
215
+ $effect(() => {
216
+ if (data != null && surface != null) {
217
+ untrack(() => {
218
+ surface.model.clear();
219
+ requestAnimationFrame(() => {
220
+ surface.model.load({data, dataType});
221
+ })
222
+ });
223
+ }
224
+ });
225
+
203
226
  onMount(async () => {
204
227
  model = model || newInstance(modelOptions || {});
205
228
 
@@ -328,7 +351,6 @@
328
351
  model.bind<EdgeUpdatedParams>(EVENT_EDGE_UPDATED, (p) => updateOverlays(p.edge.id, p));
329
352
  model.bind<EdgeRemovedParams>(EVENT_EDGE_REMOVED, (p) => removeOverlays(p.edge.id));
330
353
 
331
-
332
354
  model.bind(EVENT_GRAPH_CLEARED, () => {
333
355
  _vertices = []
334
356
  _updateVertexState()
@@ -336,12 +358,6 @@
336
358
  _updateOverlayState()
337
359
  })
338
360
 
339
- // TODO how can this be made reactive
340
- if (url != null) {
341
- model.load({ url });
342
- } else if (data != null) {
343
- model.load({ data });
344
- }
345
361
  });
346
362
 
347
363
  </script>
package/definitions.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type Snippet } from "svelte";
2
2
  import type { DOMAttributes } from "svelte/elements";
3
- import { SurfaceOptions, Vertex, Group, Node, ControlsComponentButtons, DataGeneratorFunction, type BrowserElement, Base, Size, ObjectData, DropTargetInfo, PaletteMode, SvgExportUIOptions, ImageExportUIOptions, ShapeLibraryImpl, ModelOptions, DiagramOptions, Diagram, DiagramCell, NodeMapping, GroupMapping, PortMapping, BrowserUI, EdgeMapping, OnVertexAddedCallback, CanvasDropFilter, FontSpec, BrowserUIModel, PreparedShape, PointXY, FixedElementConstraints, PopupPosition, OverlaySpec, PaperOptions, TilingStrategy, GridType, Grid } from "@visuallyjs/browser-ui";
3
+ import { SurfaceOptions, Vertex, Group, Node, ControlsComponentButtons, DataGeneratorFunction, type BrowserElement, Base, Size, ObjectData, DropTargetInfo, PaletteMode, SvgExportUIOptions, ImageExportUIOptions, ShapeLibraryImpl, ModelOptions, DiagramOptions, Diagram, DiagramCell, NodeMapping, GroupMapping, PortMapping, BrowserUI, EdgeMapping, OnVertexAddedCallback, CanvasDropFilter, FontSpec, BrowserUIModel, PreparedShape, PointXY, FixedElementConstraints, PopupPosition, OverlaySpec, PaperOptions, TilingStrategy, type GridType, Grid, type AutoEdgeConnectOptions, CanDropOnEdgeFilter } from "@visuallyjs/browser-ui";
4
4
  /**
5
5
  * Render options for a SurfaceComponent. This interface is the same as SurfaceOptions but with several vanilla-only options removed.
6
6
  */
@@ -129,6 +129,10 @@ export interface SurfaceComponentProps extends DOMAttributes<HTMLDivElement> {
129
129
  * Optional url from which to load data after the component has been mounted. If you provide this and also data, this will take precedence.
130
130
  */
131
131
  url?: string;
132
+ /**
133
+ * ID of the format that `data` or the data retrieved from `url` is expected to be in. Defaults to `JSON_DATATYPE`.
134
+ */
135
+ dataType?: string;
132
136
  /**
133
137
  * Shape library to use to render SVG shapes. Optional.
134
138
  */
@@ -179,6 +183,10 @@ export interface PaperComponentProps extends DOMAttributes<HTMLDivElement> {
179
183
  * Optional url from which to load data after the component has been mounted. If you provide this and also data, this will take precedence.
180
184
  */
181
185
  url?: string;
186
+ /**
187
+ * ID of the format that `data` or the data retrieved from `url` is expected to be in. Defaults to `JSON_DATATYPE`.
188
+ */
189
+ dataType?: string;
182
190
  /**
183
191
  * Shape library to use to render SVG shapes. Optional.
184
192
  */
@@ -326,7 +334,7 @@ export interface PaletteComponentProps extends DOMAttributes<HTMLDivElement> {
326
334
  /**
327
335
  * Whether or not to allow drop on edge. Defaults to false.
328
336
  */
329
- allowDropOnEdge?: boolean;
337
+ allowDropOnEdge?: boolean | CanDropOnEdgeFilter<any>;
330
338
  /**
331
339
  * Whether or not to allow drop on whitespace in the canvas. Defaults to true.
332
340
  */
@@ -343,6 +351,22 @@ export interface PaletteComponentProps extends DOMAttributes<HTMLDivElement> {
343
351
  * Defaults to false. When true, the palette treats nodes as if they are part of the canvas - a user can drag new items on top of existing nodes and the new item will be added to the canvas. If you want to force your users to drop on canvas whitespace, don't set this. Note that this flag will force `allowDropOnNode` to `false`.
344
352
  */
345
353
  ignoreDropOnNode?: boolean;
354
+ /**
355
+ * Whether or not to allow rotation of elements being dragged. Defaults to true.
356
+ */
357
+ allowRotation?: boolean;
358
+ /**
359
+ * The number of milliseconds required to complete a full rotation of an element when the trigger key is held down. Defaults to 2000.
360
+ */
361
+ rotationSpeed?: number;
362
+ /**
363
+ * Controls whether the palette will automatically connect a new vertex being dragged onto the canvas to existing vertices, if the shape definitions for the new vertex and/or the existing vertices have source/target elements. You can set this to simply 'true', and use defaults, or you can provide values for various options.
364
+ */
365
+ autoEdgeConnect?: boolean | AutoEdgeConnectOptions;
366
+ /**
367
+ * Whether or not to show groups in the palette. Defaults to true.
368
+ */
369
+ showGroups?: boolean;
346
370
  }
347
371
  /**
348
372
  * @group Props
@@ -450,13 +474,38 @@ export interface ShapePaletteComponentProps extends DOMAttributes<HTMLDivElement
450
474
  */
451
475
  autoExitDrawMode?: boolean;
452
476
  /**
453
- * Indicates two things: first, when one or more vertices are selected, clicking on an entry in the palette will change the type of the selected vertices to that type. Secondly, selecting an element in the canvas will cause its related shape to be selected in the palette. Defaults to true.
477
+ * When `true`, selecting an element in the canvas will cause its related shape to be selected in the palette. Defaults to true.
454
478
  */
455
479
  inspector?: boolean;
480
+ /**
481
+ * When `true`, clicking on an entry in the palette will change the type of any selected vertices to that type. Defaults to `false`.
482
+ * This is a potentially destructive operation if the properties of the new shape type are not compatible with the old one.
483
+ */
484
+ updateTypeOnPaletteTap?: boolean;
456
485
  /**
457
486
  * Optional set of prepared shapes to show in the palette. When this is provided, the palette will only render these shapes, and not the contents of the shape library.
458
487
  */
459
488
  preparedShapes?: Array<PreparedShape>;
489
+ /**
490
+ * Whether or not to allow drop on edge. Defaults to false.
491
+ */
492
+ allowDropOnEdge?: boolean | CanDropOnEdgeFilter<any>;
493
+ /**
494
+ * Whether or not to allow rotation of elements being dragged. Defaults to true.
495
+ */
496
+ allowRotation?: boolean;
497
+ /**
498
+ * The number of milliseconds required to complete a full rotation of an element when the trigger key is held down. Defaults to 2000.
499
+ */
500
+ rotationSpeed?: number;
501
+ /**
502
+ * Controls whether the palette will automatically connect a new vertex being dragged onto the canvas to existing vertices, if the shape definitions for the new vertex and/or the existing vertices have source/target elements. You can set this to simply 'true', and use defaults, or you can provide values for various options.
503
+ */
504
+ autoEdgeConnect?: boolean | AutoEdgeConnectOptions;
505
+ /**
506
+ * Whether or not to show groups in the palette. Defaults to true.
507
+ */
508
+ showGroups?: boolean;
460
509
  }
461
510
  /**
462
511
  * @group Props
@@ -699,9 +748,14 @@ export interface DiagramPaletteProps extends DOMAttributes<HTMLDivElement> {
699
748
  */
700
749
  dragSize?: Size;
701
750
  /**
702
- * Indicates that when one or more vertices are selected, clicking on an entry in the palette will change the type of the selected vertices to that type. Defaults to true.
751
+ * When `true`, selecting an element in the canvas will cause its related shape to be selected in the palette. Defaults to true.
703
752
  */
704
753
  inspector?: boolean;
754
+ /**
755
+ * When `true`, clicking on an entry in the palette will change the type of any selected vertices to that type. Defaults to `false`.
756
+ * This is a potentially destructive operation if the properties of the new shape type are not compatible with the old one.
757
+ */
758
+ updateTypeOnPaletteTap?: boolean;
705
759
  /**
706
760
  * Optional size to use for icons. Defaults to 150x100 pixels. If you provide this but not `dragSize` this size will also be used for an icon that is being dragged.
707
761
  */
@@ -756,6 +810,26 @@ export interface DiagramPaletteProps extends DOMAttributes<HTMLDivElement> {
756
810
  * Optional set of prepared shapes to show in the palette. When this is provided, the palette will only render these shapes, and not the contents of the shape library.
757
811
  */
758
812
  preparedShapes?: Array<PreparedShape>;
813
+ /**
814
+ * Whether or not to allow drop on edge. Defaults to false.
815
+ */
816
+ allowDropOnEdge?: boolean | CanDropOnEdgeFilter<any>;
817
+ /**
818
+ * Whether or not to allow rotation of elements being dragged. Defaults to true.
819
+ */
820
+ allowRotation?: boolean;
821
+ /**
822
+ * The number of milliseconds required to complete a full rotation of an element when the trigger key is held down. Defaults to 2000.
823
+ */
824
+ rotationSpeed?: number;
825
+ /**
826
+ * Controls whether the palette will automatically connect a new vertex being dragged onto the canvas to existing vertices, if the shape definitions for the new vertex and/or the existing vertices have source/target elements. You can set this to simply 'true', and use defaults, or you can provide values for various options.
827
+ */
828
+ autoEdgeConnect?: boolean | AutoEdgeConnectOptions;
829
+ /**
830
+ * Whether or not to show groups in the palette. Defaults to true.
831
+ */
832
+ showGroups?: boolean;
759
833
  }
760
834
  /**
761
835
  * Props for the ColorPicker inspector component.
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@visuallyjs/browser-ui-svelte","version":"1.2.3","description":"VisuallyJS Svelte integration for Browser UI renderer","module":"index.js","main":"index.js","types":"index.d.ts","svelte":"index.js","files":["**/*.d.ts","**/*.js","SurfaceComponent.svelte","PaperComponent.svelte","DecoratorComponent.svelte","DefaultGroupComponent.svelte","DefaultNodeComponent.svelte","MiniviewComponent.svelte","ControlsComponent.svelte","SurfaceProvider.svelte","PaperProvider.svelte","PaletteComponent.svelte","InspectorComponent.svelte","EdgeTypePickerComponent.svelte","ShapePaletteComponent.svelte","ExportControlsComponent.svelte","ShapeComponent.svelte","DiagramComponent.svelte","BarChartComponent.svelte","ColumnChartComponent.svelte","XYChartComponent.svelte","LineChartComponent.svelte","AreaChartComponent.svelte","PieChartComponent.svelte","WrapperComponent.svelte","OverlayWrapperComponent.svelte","DiagramProvider.svelte","DiagramPaletteComponent.svelte","ColorPickerComponent.svelte","ScatterChartComponent.svelte","BubbleChartComponent.svelte","GaugeChartComponent.svelte","SankeyChartComponent.svelte","SurfacePopup.svelte","GridBackgroundComponent.svelte","ImageBackgroundComponent.svelte","TiledImageBackgroundComponent.svelte"],"author":"VisuallyJs <hello@visuallyjs.com> (https://visuallyjs.com)","license":"Commercial","dependencies":{"@visuallyjs/browser-ui":"1.2.3"},"homepage":"https://visuallyjs.com/svelte","bugs":"https://github.com/visuallyjs/visuallyjs/issues"}
1
+ {"name":"@visuallyjs/browser-ui-svelte","version":"1.2.5","description":"VisuallyJS Svelte integration for Browser UI renderer","module":"index.js","main":"index.js","types":"index.d.ts","svelte":"index.js","files":["**/*.d.ts","**/*.js","SurfaceComponent.svelte","PaperComponent.svelte","DecoratorComponent.svelte","DefaultGroupComponent.svelte","DefaultNodeComponent.svelte","MiniviewComponent.svelte","ControlsComponent.svelte","SurfaceProvider.svelte","PaperProvider.svelte","PaletteComponent.svelte","InspectorComponent.svelte","EdgeTypePickerComponent.svelte","ShapePaletteComponent.svelte","ExportControlsComponent.svelte","ShapeComponent.svelte","DiagramComponent.svelte","BarChartComponent.svelte","ColumnChartComponent.svelte","XYChartComponent.svelte","LineChartComponent.svelte","AreaChartComponent.svelte","PieChartComponent.svelte","WrapperComponent.svelte","OverlayWrapperComponent.svelte","DiagramProvider.svelte","DiagramPaletteComponent.svelte","ColorPickerComponent.svelte","ScatterChartComponent.svelte","BubbleChartComponent.svelte","GaugeChartComponent.svelte","SankeyChartComponent.svelte","SurfacePopup.svelte","GridBackgroundComponent.svelte","ImageBackgroundComponent.svelte","TiledImageBackgroundComponent.svelte"],"author":"VisuallyJs <hello@visuallyjs.com> (https://visuallyjs.com)","license":"Commercial","dependencies":{"@visuallyjs/browser-ui":"1.2.5"},"homepage":"https://visuallyjs.com/svelte","bugs":"https://github.com/visuallyjs/visuallyjs/issues"}