@visuallyjs/browser-ui-svelte 1.0.3 → 1.1.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.
@@ -100,7 +100,7 @@
100
100
  let propsToSet:Record<string, any> = {
101
101
  data: modelObject.data,
102
102
  model,
103
- surface,
103
+ ui:surface,
104
104
  componentId: modelObject.getFullId(),
105
105
  vertex: modelObject,
106
106
  eventInfo,
@@ -194,7 +194,7 @@
194
194
  // asynchronous-y reasons. $redrawEveryConnection only redraws
195
195
  // edges and does not update element positions so it's
196
196
  // reasonably quick.
197
- surface.bind(EVENT_RENDER_END, () => setTimeout(() => surface.router.$redrawEveryConnection()))
197
+ surface.bind(EVENT_RENDER_END, () => setTimeout(() => surface.$redrawEveryConnection()))
198
198
 
199
199
  if (surfaceContext != null) {
200
200
  surfaceContext.set(surface);
@@ -260,7 +260,7 @@
260
260
  {#each vertexState.vertices as vertex (vertex.id)}
261
261
  <WrapperComponent component={vertex.component}
262
262
  data={vertex.props.data}
263
- surface={surface}
263
+ ui={surface}
264
264
  def={vertex.def}
265
265
  vertex={vertex.vertex}
266
266
  className={vertex.props.className}/>
@@ -4,24 +4,24 @@
4
4
  // This is a placeholder component that the surface uses to render each vertex.
5
5
 
6
6
  import {onMount} from "svelte";
7
- import {type BrowserElement} from "@visuallyjs/browser-ui";
7
+ import {type BrowserElement, BrowserUI} from "@visuallyjs/browser-ui";
8
8
 
9
- let {component, vertex, surface, def, data, className} = $props()
9
+ let {component, vertex, ui, def, data, className} = $props()
10
10
  let el:BrowserElement
11
11
 
12
12
  // svelte wants uppercase here. So we just assign to an uppercase var, which we use in the
13
13
  // template
14
14
  const ComponentToRender = component
15
15
 
16
- const _surface = $state.raw(surface)
16
+ const _ui = $state.raw(ui) as BrowserUI
17
17
 
18
18
  onMount(async () => {
19
- surface.$vertexRendered(vertex, el, def)
19
+ ui.$vertexRendered(vertex, el, def)
20
20
  })
21
21
 
22
22
 
23
23
  </script>
24
24
 
25
25
  <div bind:this={el} class={className}>
26
- <ComponentToRender this={component} data={data} surface={_surface} vertex={vertex} model={_surface.model}/>
26
+ <ComponentToRender this={component} data={data} ui={_ui} vertex={vertex} model={_ui.model}/>
27
27
  </div>
package/definitions.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { DOMAttributes } from "svelte/elements";
2
- import { SurfaceOptions, Vertex, Group, Node, ControlsComponentButtons, DataGeneratorFunction, type BrowserElement, Base, Size, ObjectData, DropTargetInfo, PaletteMode, SvgExportUIOptions, ImageExportUIOptions, ShapeLibraryImpl, ModelOptions, DiagramOptions, ColumnChartOptions, BarChartOptions, CategoryValueChartOptions, Diagram, DiagramCell, NodeMapping, GroupMapping, PortMapping, Surface, EdgeMapping, OnVertexAddedCallback, CanvasDropFilter, LineChartOptions, AreaChartOptions, PieChartOptions, ScatterChartOptions, BubbleChartOptions, GaugeChartOptions, SankeyOptions, FontSpec, BrowserUIModel, PreparedShape, ChartModelFilter, VisuallyJsDefaultJSON, PointXY, FixedElementConstraints } from "@visuallyjs/browser-ui";
2
+ import { SurfaceOptions, Vertex, Group, Node, ControlsComponentButtons, DataGeneratorFunction, type BrowserElement, Base, Size, ObjectData, DropTargetInfo, PaletteMode, SvgExportUIOptions, ImageExportUIOptions, ShapeLibraryImpl, ModelOptions, DiagramOptions, ColumnChartOptions, BarChartOptions, CategoryValueChartOptions, Diagram, DiagramCell, NodeMapping, GroupMapping, PortMapping, BrowserUI, EdgeMapping, OnVertexAddedCallback, CanvasDropFilter, LineChartOptions, AreaChartOptions, PieChartOptions, ScatterChartOptions, BubbleChartOptions, GaugeChartOptions, SankeyOptions, FontSpec, BrowserUIModel, PreparedShape, ChartModelFilter, VisuallyJsDefaultJSON, PointXY, FixedElementConstraints } from "@visuallyjs/browser-ui";
3
3
  import { type Snippet } from "svelte";
4
4
  /**
5
5
  * Render options for a SurfaceComponent. This interface is the same as SurfaceOptions but with several vanilla-only options removed.
@@ -9,7 +9,7 @@ export interface SvelteSurfaceRenderOptions extends Omit<SurfaceOptions, "direct
9
9
  /**
10
10
  * Definition of a node - its component, and behaviour.
11
11
  */
12
- export interface SvelteNodeMapping extends Omit<NodeMapping<any>, "template" | "templateId" | "parameters"> {
12
+ export interface SvelteNodeMapping extends Omit<NodeMapping<any>, "templateIdResolver" | "template" | "templateId" | "parameters"> {
13
13
  /**
14
14
  * component used to render this node type. Optional; if you do not supply it a default component will be used.
15
15
  */
@@ -18,7 +18,7 @@ export interface SvelteNodeMapping extends Omit<NodeMapping<any>, "template" | "
18
18
  /**
19
19
  * Definition of a group - its component, and behaviour.
20
20
  */
21
- export interface SvelteGroupMapping extends Omit<GroupMapping<any>, "template" | "templateId" | "parameters"> {
21
+ export interface SvelteGroupMapping extends Omit<GroupMapping<any>, "templateIdResolver" | "template" | "templateId" | "parameters"> {
22
22
  /**
23
23
  * component used to render this group type. Optional; if you do not supply it a default component will be used.
24
24
  */
@@ -27,7 +27,7 @@ export interface SvelteGroupMapping extends Omit<GroupMapping<any>, "template" |
27
27
  /**
28
28
  * Definition of a port - its component, and behaviour.
29
29
  */
30
- export interface SveltePortMapping extends Omit<PortMapping<any>, "template" | "templateId" | "parameters"> {
30
+ export interface SveltePortMapping extends Omit<PortMapping<any>, "templateIdResolver" | "template" | "templateId" | "parameters"> {
31
31
  /**
32
32
  * component used to render this port type. Optional; if you do not supply it a default component will be used.
33
33
  */
@@ -817,7 +817,7 @@ export interface ColorPickerComponentProps extends DOMAttributes<HTMLDivElement>
817
817
  */
818
818
  export interface SvelteWrapperProps {
819
819
  data: ObjectData;
820
- surface: Surface;
820
+ ui: BrowserUI;
821
821
  vertex: Vertex;
822
822
  model: BrowserUIModel;
823
823
  }
package/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export * from './diagram-store';
11
11
  export * from './surface-store';
12
12
  export * from './inspector-store';
13
13
  export * from './definitions';
14
+ export * from './use-zoom.svelte';
14
15
  import { BrowserElement, BrowserUIModel, BrowserUIOptions, TemplateRenderer, ModelOptions } from "@visuallyjs/browser-ui";
15
16
  /**
16
17
  * Extension of VisuallyJsModel suitable for use with the Svelte integration.
package/index.js CHANGED
@@ -11,6 +11,7 @@ export * from './diagram-store';
11
11
  export * from './surface-store';
12
12
  export * from './inspector-store';
13
13
  export * from './definitions';
14
+ export * from './use-zoom.svelte';
14
15
  import { BrowserUIModel, log } from "@visuallyjs/browser-ui";
15
16
  /**
16
17
  * Extension of VisuallyJsModel suitable for use with the Svelte integration.
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@visuallyjs/browser-ui-svelte","version":"1.0.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","DecoratorComponent.svelte","DefaultGroupComponent.svelte","DefaultNodeComponent.svelte","MiniviewComponent.svelte","ControlsComponent.svelte","SurfaceProvider.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","DiagramProvider.svelte","DiagramPaletteComponent.svelte","ColorPickerComponent.svelte","ScatterChartComponent.svelte","BubbleChartComponent.svelte","GaugeChartComponent.svelte","SankeyChartComponent.svelte"],"author":"VisuallyJs <hello@visuallyjs.com> (https://visuallyjs.com)","license":"Commercial","dependencies":{"@visuallyjs/browser-ui":"1.0.3"},"homepage":"https://visuallyjs.com/svelte","bugs":"https://github.com/visuallyjs/visuallyjs/issues"}
1
+ {"name":"@visuallyjs/browser-ui-svelte","version":"1.1.0","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","DecoratorComponent.svelte","DefaultGroupComponent.svelte","DefaultNodeComponent.svelte","MiniviewComponent.svelte","ControlsComponent.svelte","SurfaceProvider.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","DiagramProvider.svelte","DiagramPaletteComponent.svelte","ColorPickerComponent.svelte","ScatterChartComponent.svelte","BubbleChartComponent.svelte","GaugeChartComponent.svelte","SankeyChartComponent.svelte"],"author":"VisuallyJs <hello@visuallyjs.com> (https://visuallyjs.com)","license":"Commercial","dependencies":{"@visuallyjs/browser-ui":"1.1.0"},"homepage":"https://visuallyjs.com/svelte","bugs":"https://github.com/visuallyjs/visuallyjs/issues"}
@@ -0,0 +1,9 @@
1
+ import { BrowserUI } from '@visuallyjs/browser-ui';
2
+ /**
3
+ * Creates a reactive zoom state for a VisuallyJS UI
4
+ * @param ui The Surface instance provided via props.
5
+ * @group Hooks
6
+ */
7
+ export declare function useZoom(ui: BrowserUI): {
8
+ readonly current: number;
9
+ };
@@ -0,0 +1,28 @@
1
+ import { EVENT_ZOOM } from '@visuallyjs/browser-ui';
2
+ /**
3
+ * Creates a reactive zoom state for a VisuallyJS UI
4
+ * @param ui The Surface instance provided via props.
5
+ * @group Hooks
6
+ */
7
+ export function useZoom(ui) {
8
+ // Define reactive state
9
+ debugger;
10
+ let zoom = $state(ui.getZoom());
11
+ // Manage event listener lifecycle
12
+ $effect(() => {
13
+ const handler = (p) => {
14
+ zoom = p.zoom;
15
+ };
16
+ ui.bind(EVENT_ZOOM, handler);
17
+ // Auto-cleanup when the component/effect is destroyed
18
+ return () => {
19
+ ui.unbind(EVENT_ZOOM, handler);
20
+ };
21
+ });
22
+ // Return an object with a getter to maintain reactivity across function boundaries
23
+ return {
24
+ get current() {
25
+ return zoom;
26
+ }
27
+ };
28
+ }