@visuallyjs/browser-ui-svelte 1.2.0 → 1.2.2
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/ColorPickerComponent.svelte +2 -2
- package/EdgeTypePickerComponent.svelte +1 -1
- package/GridBackgroundComponent.svelte +39 -0
- package/ImageBackgroundComponent.svelte +37 -0
- package/OverlayWrapperComponent.svelte +35 -0
- package/PaperComponent.svelte +367 -0
- package/PaperProvider.svelte +11 -0
- package/SurfaceComponent.svelte +109 -11
- package/SurfacePopup.svelte +37 -0
- package/TiledImageBackgroundComponent.svelte +36 -0
- package/WrapperComponent.svelte +3 -1
- package/ambient.d.ts +7 -0
- package/components.d.ts +7 -0
- package/components.js +7 -0
- package/definitions.d.ts +214 -6
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +1 -1
- package/surface-store.d.ts +21 -1
- package/surface-store.js +41 -0
- package/use-diagram.svelte.d.ts +1 -1
- package/use-diagram.svelte.js +1 -1
- package/use-paper.svelte.d.ts +7 -0
- package/use-paper.svelte.js +18 -0
- package/use-surface.svelte.d.ts +1 -1
- package/use-surface.svelte.js +1 -1
package/surface-store.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Surface } from "@visuallyjs/browser-ui";
|
|
1
|
+
import type { Paper, Surface } from "@visuallyjs/browser-ui";
|
|
2
2
|
import { BrowserUISvelteModel } from "./index";
|
|
3
3
|
/**
|
|
4
4
|
* Key for the surface context
|
|
@@ -17,11 +17,24 @@ export interface SurfaceRef {
|
|
|
17
17
|
set: (surface: Surface) => void;
|
|
18
18
|
listen: (l: (s: Surface) => any) => void;
|
|
19
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Handle for a paper - use `set` to set the paper and `listen` to register a listener.
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export interface PaperRef {
|
|
25
|
+
set: (paper: Paper) => void;
|
|
26
|
+
listen: (l: (s: Paper) => any) => void;
|
|
27
|
+
}
|
|
20
28
|
/**
|
|
21
29
|
* Create a surface context, and set it on Svelte via `setContext`.
|
|
22
30
|
* @internal
|
|
23
31
|
*/
|
|
24
32
|
export declare function internal_createSurfaceContext(): SurfaceRef;
|
|
33
|
+
/**
|
|
34
|
+
* Create a paper context, and set it on Svelte via `setContext`.
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export declare function internal_createPaperContext(): PaperRef;
|
|
25
38
|
/**
|
|
26
39
|
* Gets the current surface context from Svelte, optionally creating it if it does not exist. The Surface and the SurfaceProvider both set `doNotCreate` to false; other components such as miniview/controls must set it to true.
|
|
27
40
|
* This method is NOT to be invoked by users of the API. Use {@link useSurface} to access the current Surface.
|
|
@@ -29,6 +42,13 @@ export declare function internal_createSurfaceContext(): SurfaceRef;
|
|
|
29
42
|
* @internal
|
|
30
43
|
*/
|
|
31
44
|
export declare function internal_getSurfaceContext(doNotCreate: boolean): SurfaceRef;
|
|
45
|
+
/**
|
|
46
|
+
* Gets the current paper context from Svelte, optionally creating it if it does not exist. The Paper and the PaperProvider both set `doNotCreate` to false; other components such as miniview/controls must set it to true.
|
|
47
|
+
* This method is NOT to be invoked by users of the API. Use {@link usePaper} to access the current Paper.
|
|
48
|
+
* @param doNotCreate
|
|
49
|
+
* @internal
|
|
50
|
+
*/
|
|
51
|
+
export declare function internal_getPaperContext(doNotCreate: boolean): PaperRef;
|
|
32
52
|
/**
|
|
33
53
|
* Hook to expose the current model. This hook is asynchronous and returns a Promise.
|
|
34
54
|
* @group Hooks
|
package/surface-store.js
CHANGED
|
@@ -29,6 +29,30 @@ export function internal_createSurfaceContext() {
|
|
|
29
29
|
setContext(STORE_KEY, ref);
|
|
30
30
|
return ref;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a paper context, and set it on Svelte via `setContext`.
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
export function internal_createPaperContext() {
|
|
37
|
+
const listeners = [];
|
|
38
|
+
const handle = { current: null };
|
|
39
|
+
const ref = {
|
|
40
|
+
set: (paper) => {
|
|
41
|
+
handle.current = paper;
|
|
42
|
+
listeners.forEach(l => l(paper));
|
|
43
|
+
},
|
|
44
|
+
listen: (l) => {
|
|
45
|
+
if (handle.current == null) {
|
|
46
|
+
listeners.push(l);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
l(handle.current);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
setContext(STORE_KEY, ref);
|
|
54
|
+
return ref;
|
|
55
|
+
}
|
|
32
56
|
/**
|
|
33
57
|
* Gets the current surface context from Svelte, optionally creating it if it does not exist. The Surface and the SurfaceProvider both set `doNotCreate` to false; other components such as miniview/controls must set it to true.
|
|
34
58
|
* This method is NOT to be invoked by users of the API. Use {@link useSurface} to access the current Surface.
|
|
@@ -42,17 +66,34 @@ export function internal_getSurfaceContext(doNotCreate) {
|
|
|
42
66
|
}
|
|
43
67
|
return ctx;
|
|
44
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Gets the current paper context from Svelte, optionally creating it if it does not exist. The Paper and the PaperProvider both set `doNotCreate` to false; other components such as miniview/controls must set it to true.
|
|
71
|
+
* This method is NOT to be invoked by users of the API. Use {@link usePaper} to access the current Paper.
|
|
72
|
+
* @param doNotCreate
|
|
73
|
+
* @internal
|
|
74
|
+
*/
|
|
75
|
+
export function internal_getPaperContext(doNotCreate) {
|
|
76
|
+
let ctx = getContext(STORE_KEY);
|
|
77
|
+
if (ctx == null && !doNotCreate) {
|
|
78
|
+
ctx = internal_createPaperContext();
|
|
79
|
+
}
|
|
80
|
+
return ctx;
|
|
81
|
+
}
|
|
45
82
|
/**
|
|
46
83
|
* Hook to expose the current model. This hook is asynchronous and returns a Promise.
|
|
47
84
|
* @group Hooks
|
|
48
85
|
*/
|
|
49
86
|
export function useVisuallyJsModel() {
|
|
50
87
|
const ref = internal_getSurfaceContext(true);
|
|
88
|
+
const paperRef = internal_getPaperContext(true);
|
|
51
89
|
const diagramRef = internal_getDiagramContext(true);
|
|
52
90
|
return new Promise((resolve, reject) => {
|
|
53
91
|
if (ref != null) {
|
|
54
92
|
ref.listen((s) => resolve(s.model));
|
|
55
93
|
}
|
|
94
|
+
else if (paperRef != null) {
|
|
95
|
+
paperRef.listen((s) => resolve(s.model));
|
|
96
|
+
}
|
|
56
97
|
else if (diagramRef != null) {
|
|
57
98
|
diagramRef.listen((d) => resolve(d.model));
|
|
58
99
|
}
|
package/use-diagram.svelte.d.ts
CHANGED
package/use-diagram.svelte.js
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { internal_getPaperContext } from "./surface-store";
|
|
2
|
+
/**
|
|
3
|
+
* Hook to access the current Paper.
|
|
4
|
+
* @group Hooks
|
|
5
|
+
*/
|
|
6
|
+
export function usePaper() {
|
|
7
|
+
const ctx = internal_getPaperContext(true);
|
|
8
|
+
let paper = $state(null);
|
|
9
|
+
if (ctx != null) {
|
|
10
|
+
ctx.listen((s) => paper = s);
|
|
11
|
+
}
|
|
12
|
+
// Return an object with a getter to maintain reactivity across function boundaries
|
|
13
|
+
return {
|
|
14
|
+
get current() {
|
|
15
|
+
return paper;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
}
|
package/use-surface.svelte.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Surface } from '@visuallyjs/browser-ui';
|
|
2
2
|
import { RefObject } from "./definitions";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Hook to access the current Surface
|
|
5
5
|
* @group Hooks
|
|
6
6
|
*/
|
|
7
7
|
export declare function useSurface(): RefObject<Surface>;
|