@snaptrude/plugin-client 0.0.2 → 0.0.4
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/dist/api/core/geom/arc.d.ts +5 -0
- package/dist/api/core/geom/arc.d.ts.map +1 -0
- package/dist/api/core/geom/curve.d.ts +5 -0
- package/dist/api/core/geom/curve.d.ts.map +1 -0
- package/dist/api/core/geom/index.d.ts +17 -0
- package/dist/api/core/geom/index.d.ts.map +1 -0
- package/dist/api/core/geom/line.d.ts +5 -0
- package/dist/api/core/geom/line.d.ts.map +1 -0
- package/dist/api/core/geom/profile.d.ts +7 -0
- package/dist/api/core/geom/profile.d.ts.map +1 -0
- package/dist/api/core/index.d.ts +11 -0
- package/dist/api/core/index.d.ts.map +1 -0
- package/dist/api/core/math/index.d.ts +11 -0
- package/dist/api/core/math/index.d.ts.map +1 -0
- package/dist/api/core/math/quat.d.ts +5 -0
- package/dist/api/core/math/quat.d.ts.map +1 -0
- package/dist/api/core/math/vec3.d.ts +5 -0
- package/dist/api/core/math/vec3.d.ts.map +1 -0
- package/dist/api/entity/index.d.ts +3 -0
- package/dist/api/entity/index.d.ts.map +1 -1
- package/dist/api/entity/space.d.ts +3 -2
- package/dist/api/entity/space.d.ts.map +1 -1
- package/dist/api/entity/story.d.ts +9 -0
- package/dist/api/entity/story.d.ts.map +1 -0
- package/dist/api/index.d.ts +6 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/units/index.d.ts +7 -0
- package/dist/api/units/index.d.ts.map +1 -0
- package/dist/index.cjs +274 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +259 -8
- package/dist/index.js.map +1 -1
- package/dist/plugin-worker.d.ts +48 -0
- package/dist/plugin-worker.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/api/core/geom/arc.ts +7 -0
- package/src/api/core/geom/curve.ts +7 -0
- package/src/api/core/geom/index.ts +25 -0
- package/src/api/core/geom/line.ts +7 -0
- package/src/api/core/geom/profile.ts +17 -0
- package/src/api/core/index.ts +17 -0
- package/src/api/core/math/index.ts +17 -0
- package/src/api/core/math/quat.ts +7 -0
- package/src/api/core/math/vec3.ts +7 -0
- package/src/api/entity/index.ts +4 -0
- package/src/api/entity/space.ts +23 -5
- package/src/api/entity/story.ts +66 -0
- package/src/api/index.ts +8 -0
- package/src/api/units/index.ts +34 -0
- package/src/index.ts +1 -0
- package/src/plugin-worker.ts +91 -0
- package/tsconfig.json +1 -1
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PluginMathApi } from "@snaptrude/plugin-core"
|
|
2
|
+
import { ClientVec3Api } from "./vec3"
|
|
3
|
+
import { ClientQuatApi } from "./quat"
|
|
4
|
+
|
|
5
|
+
export class ClientMathApi extends PluginMathApi {
|
|
6
|
+
public vec3: ClientVec3Api
|
|
7
|
+
public quat: ClientQuatApi
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
super()
|
|
11
|
+
this.vec3 = new ClientVec3Api()
|
|
12
|
+
this.quat = new ClientQuatApi()
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export * from "./vec3"
|
|
17
|
+
export * from "./quat"
|
package/src/api/entity/index.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { PluginEntityApi } from "@snaptrude/plugin-core"
|
|
2
2
|
import { ClientSpaceApi } from "./space"
|
|
3
|
+
import { ClientStoryApi } from "./story"
|
|
3
4
|
|
|
4
5
|
export class ClientEntityApi extends PluginEntityApi {
|
|
5
6
|
public space: ClientSpaceApi
|
|
7
|
+
public story: ClientStoryApi
|
|
6
8
|
|
|
7
9
|
constructor() {
|
|
8
10
|
super()
|
|
9
11
|
this.space = new ClientSpaceApi()
|
|
12
|
+
this.story = new ClientStoryApi()
|
|
10
13
|
}
|
|
11
14
|
}
|
|
12
15
|
|
|
13
16
|
export * from "./space"
|
|
17
|
+
export * from "./story"
|
package/src/api/entity/space.ts
CHANGED
|
@@ -2,10 +2,12 @@ import {
|
|
|
2
2
|
PluginSpaceApi,
|
|
3
3
|
PluginSpaceCreateRectangularArgs,
|
|
4
4
|
PluginSpaceCreateRectangularResult,
|
|
5
|
+
PluginSpaceCreateFromProfileArgs,
|
|
6
|
+
PluginSpaceCreateFromProfileResult,
|
|
5
7
|
PluginSpaceDeleteByIdArgs,
|
|
6
8
|
PluginSpaceDeleteByIdResult,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
PluginSpaceGetArgs,
|
|
10
|
+
PluginSpaceGetResult,
|
|
9
11
|
PluginSpaceGetAllResult,
|
|
10
12
|
} from "@snaptrude/plugin-core"
|
|
11
13
|
import { getHostApi } from "../../host-api"
|
|
@@ -29,13 +31,29 @@ export class ClientSpaceApi extends PluginSpaceApi {
|
|
|
29
31
|
})
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
public async
|
|
34
|
+
public async createFromProfile({
|
|
35
|
+
profile,
|
|
36
|
+
extrudeHeight,
|
|
37
|
+
position,
|
|
38
|
+
}: PluginSpaceCreateFromProfileArgs): Promise<PluginSpaceCreateFromProfileResult> {
|
|
39
|
+
const hostApi = getHostApi()
|
|
40
|
+
return hostApi.call({
|
|
41
|
+
method: "entity.space.createFromProfile",
|
|
42
|
+
args: {
|
|
43
|
+
profile,
|
|
44
|
+
extrudeHeight,
|
|
45
|
+
position,
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public async get({
|
|
33
51
|
spaceId,
|
|
34
52
|
properties,
|
|
35
|
-
}:
|
|
53
|
+
}: PluginSpaceGetArgs): Promise<PluginSpaceGetResult> {
|
|
36
54
|
const hostApi = getHostApi()
|
|
37
55
|
return hostApi.call({
|
|
38
|
-
method: "entity.space.
|
|
56
|
+
method: "entity.space.get",
|
|
39
57
|
args: {
|
|
40
58
|
spaceId,
|
|
41
59
|
properties,
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PluginStoryApi,
|
|
3
|
+
PluginStoryGetArgs,
|
|
4
|
+
PluginStoryGetResult,
|
|
5
|
+
PluginStoryGetAllResult,
|
|
6
|
+
PluginStoryCreateArgs,
|
|
7
|
+
PluginStoryCreateResult,
|
|
8
|
+
PluginStoryUpdateArgs,
|
|
9
|
+
PluginStoryUpdateResult,
|
|
10
|
+
} from "@snaptrude/plugin-core"
|
|
11
|
+
import { getHostApi } from "../../host-api"
|
|
12
|
+
|
|
13
|
+
export class ClientStoryApi extends PluginStoryApi {
|
|
14
|
+
constructor() {
|
|
15
|
+
super()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public async get({
|
|
19
|
+
storyValue,
|
|
20
|
+
properties,
|
|
21
|
+
}: PluginStoryGetArgs): Promise<PluginStoryGetResult> {
|
|
22
|
+
const hostApi = getHostApi()
|
|
23
|
+
return hostApi.call({
|
|
24
|
+
method: "entity.story.get",
|
|
25
|
+
args: {
|
|
26
|
+
storyValue,
|
|
27
|
+
properties,
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public async getAll(): Promise<PluginStoryGetAllResult> {
|
|
33
|
+
const hostApi = getHostApi()
|
|
34
|
+
return hostApi.call({
|
|
35
|
+
method: "entity.story.getAll",
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public async create({
|
|
40
|
+
storyValue,
|
|
41
|
+
height,
|
|
42
|
+
}: PluginStoryCreateArgs): Promise<PluginStoryCreateResult> {
|
|
43
|
+
const hostApi = getHostApi()
|
|
44
|
+
return hostApi.call({
|
|
45
|
+
method: "entity.story.create",
|
|
46
|
+
args: {
|
|
47
|
+
storyValue,
|
|
48
|
+
height,
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public async update({
|
|
54
|
+
storyValue,
|
|
55
|
+
height,
|
|
56
|
+
}: PluginStoryUpdateArgs): Promise<PluginStoryUpdateResult> {
|
|
57
|
+
const hostApi = getHostApi()
|
|
58
|
+
return hostApi.call({
|
|
59
|
+
method: "entity.story.update",
|
|
60
|
+
args: {
|
|
61
|
+
storyValue,
|
|
62
|
+
height,
|
|
63
|
+
},
|
|
64
|
+
})
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/api/index.ts
CHANGED
|
@@ -1,17 +1,23 @@
|
|
|
1
|
+
import { ClientCoreApi } from "./core"
|
|
1
2
|
import { ClientEntityApi } from "./entity"
|
|
2
3
|
import { ClientToolsApi } from "./tools"
|
|
4
|
+
import { ClientUnitsApi } from "./units"
|
|
3
5
|
import { PluginApi } from "@snaptrude/plugin-core"
|
|
4
6
|
|
|
5
7
|
export class ClientPluginApi extends PluginApi {
|
|
6
8
|
private static instance: ClientPluginApi
|
|
7
9
|
|
|
10
|
+
public core: ClientCoreApi
|
|
8
11
|
public tools: ClientToolsApi
|
|
9
12
|
public entity: ClientEntityApi
|
|
13
|
+
public units: ClientUnitsApi
|
|
10
14
|
|
|
11
15
|
private constructor() {
|
|
12
16
|
super()
|
|
17
|
+
this.core = new ClientCoreApi()
|
|
13
18
|
this.tools = new ClientToolsApi()
|
|
14
19
|
this.entity = new ClientEntityApi()
|
|
20
|
+
this.units = new ClientUnitsApi()
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
static getInstance(): ClientPluginApi {
|
|
@@ -22,5 +28,7 @@ export class ClientPluginApi extends PluginApi {
|
|
|
22
28
|
}
|
|
23
29
|
}
|
|
24
30
|
|
|
31
|
+
export * from "./core"
|
|
25
32
|
export * from "./entity"
|
|
26
33
|
export * from "./tools"
|
|
34
|
+
export * from "./units"
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PluginUnitsApi,
|
|
3
|
+
PluginUnitsConvertFromArgs,
|
|
4
|
+
PluginUnitsConvertFromResult,
|
|
5
|
+
PluginUnitsConvertToArgs,
|
|
6
|
+
PluginUnitsConvertToResult,
|
|
7
|
+
} from "@snaptrude/plugin-core"
|
|
8
|
+
import { getHostApi } from "../../host-api"
|
|
9
|
+
|
|
10
|
+
export class ClientUnitsApi extends PluginUnitsApi {
|
|
11
|
+
constructor() {
|
|
12
|
+
super()
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public async convertFrom(
|
|
16
|
+
args: PluginUnitsConvertFromArgs,
|
|
17
|
+
): Promise<PluginUnitsConvertFromResult> {
|
|
18
|
+
const hostApi = getHostApi()
|
|
19
|
+
return hostApi.call({
|
|
20
|
+
method: "units.convertFrom",
|
|
21
|
+
args,
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public async convertTo(
|
|
26
|
+
args: PluginUnitsConvertToArgs,
|
|
27
|
+
): Promise<PluginUnitsConvertToResult> {
|
|
28
|
+
const hostApi = getHostApi()
|
|
29
|
+
return hostApi.call({
|
|
30
|
+
method: "units.convertTo",
|
|
31
|
+
args,
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as Comlink from "comlink"
|
|
2
|
+
|
|
3
|
+
export interface UIMessage {
|
|
4
|
+
action: string
|
|
5
|
+
payload: unknown
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface PluginConfig {
|
|
9
|
+
pluginId: string
|
|
10
|
+
permissions: string[]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Base class for Snaptrude plugin workers.
|
|
15
|
+
*
|
|
16
|
+
* Handles Comlink wiring, host communication, and the standard lifecycle
|
|
17
|
+
* methods (`init`, `destroy`, `ping`, `onUIMessage`). Subclass this and
|
|
18
|
+
* override only the methods you need — then call `start()` to expose the
|
|
19
|
+
* worker API.
|
|
20
|
+
*
|
|
21
|
+
* The plugin ID is received automatically from the host during
|
|
22
|
+
* initialization — no need to pass it manually.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { PluginWorker } from "@snaptrude/plugin-client";
|
|
27
|
+
*
|
|
28
|
+
* class MyPlugin extends PluginWorker {
|
|
29
|
+
* async onUIMessage(message: UIMessage) {
|
|
30
|
+
* // handle messages from the UI panel
|
|
31
|
+
* }
|
|
32
|
+
* }
|
|
33
|
+
*
|
|
34
|
+
* new MyPlugin().start();
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export abstract class PluginWorker {
|
|
38
|
+
protected pluginId!: string
|
|
39
|
+
private hostAPI: Comlink.Remote<Record<string, unknown>>
|
|
40
|
+
|
|
41
|
+
constructor() {
|
|
42
|
+
this.hostAPI = Comlink.wrap<Record<string, unknown>>(
|
|
43
|
+
self as unknown as Comlink.Endpoint
|
|
44
|
+
)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
protected sendToUI(action: string, payload: unknown): void {
|
|
48
|
+
;(this.hostAPI as Record<string, any>).ui.sendToUI({ action, payload })
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async init(): Promise<void> {
|
|
52
|
+
console.log(this.pluginId, "init() called")
|
|
53
|
+
console.log(this.pluginId, "Initialization complete")
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async destroy(): Promise<void> {
|
|
57
|
+
console.log(this.pluginId, "destroy() called — cleaning up")
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async ping(): Promise<string> {
|
|
61
|
+
return "pong"
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async onUIMessage(_message: UIMessage): Promise<void> {
|
|
65
|
+
// Override in subclass to handle UI messages
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Expose the worker API via Comlink and start listening.
|
|
70
|
+
* Call this once after constructing the plugin instance.
|
|
71
|
+
*
|
|
72
|
+
* The host calls `init(config)` with `{ pluginId, permissions }`,
|
|
73
|
+
* which is captured here to set `this.pluginId` before the
|
|
74
|
+
* subclass's `init()` runs.
|
|
75
|
+
*/
|
|
76
|
+
start(): void {
|
|
77
|
+
Comlink.expose(
|
|
78
|
+
{
|
|
79
|
+
init: (config: PluginConfig) => {
|
|
80
|
+
this.pluginId = config.pluginId
|
|
81
|
+
return this.init()
|
|
82
|
+
},
|
|
83
|
+
destroy: () => this.destroy(),
|
|
84
|
+
ping: () => this.ping(),
|
|
85
|
+
onUIMessage: (message: UIMessage) => this.onUIMessage(message),
|
|
86
|
+
},
|
|
87
|
+
self as unknown as Comlink.Endpoint
|
|
88
|
+
)
|
|
89
|
+
console.log("Worker loaded, API exposed via Comlink")
|
|
90
|
+
}
|
|
91
|
+
}
|