@snaptrude/plugin-client 0.0.1
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/entity/index.d.ts +8 -0
- package/dist/api/entity/index.d.ts.map +1 -0
- package/dist/api/entity/space.d.ts +8 -0
- package/dist/api/entity/space.d.ts.map +1 -0
- package/dist/api/index.d.ts +13 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/tools/index.d.ts +11 -0
- package/dist/api/tools/index.d.ts.map +1 -0
- package/dist/api/tools/selection.d.ts +6 -0
- package/dist/api/tools/selection.d.ts.map +1 -0
- package/dist/api/tools/transform.d.ts +7 -0
- package/dist/api/tools/transform.d.ts.map +1 -0
- package/dist/host-api.d.ts +8 -0
- package/dist/host-api.d.ts.map +1 -0
- package/dist/index.cjs +212 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +171 -0
- package/dist/index.js.map +1 -0
- package/package.json +33 -0
- package/src/api/entity/index.ts +13 -0
- package/src/api/entity/space.ts +56 -0
- package/src/api/index.ts +26 -0
- package/src/api/tools/index.ts +17 -0
- package/src/api/tools/selection.ts +15 -0
- package/src/api/tools/transform.ts +44 -0
- package/src/host-api.ts +27 -0
- package/src/index.ts +11 -0
- package/tsconfig.json +16 -0
- package/tsup.config.ts +13 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PluginEntityApi } from "@snaptrude/plugin-core";
|
|
2
|
+
import { ClientSpaceApi } from "./space";
|
|
3
|
+
export declare class ClientEntityApi extends PluginEntityApi {
|
|
4
|
+
space: ClientSpaceApi;
|
|
5
|
+
constructor();
|
|
6
|
+
}
|
|
7
|
+
export * from "./space";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/entity/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AAExC,qBAAa,eAAgB,SAAQ,eAAe;IAC3C,KAAK,EAAE,cAAc,CAAA;;CAM7B;AAED,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PluginSpaceApi, PluginSpaceCreateRectangularArgs, PluginSpaceCreateRectangularResult, PluginSpaceDeleteByIdArgs, PluginSpaceDeleteByIdResult, PluginSpaceGetByIdArgs, PluginSpaceGetByIdResult } from "@snaptrude/plugin-core";
|
|
2
|
+
export declare class ClientSpaceApi extends PluginSpaceApi {
|
|
3
|
+
constructor();
|
|
4
|
+
createRectangular({ position, dimensions, }: PluginSpaceCreateRectangularArgs): Promise<PluginSpaceCreateRectangularResult>;
|
|
5
|
+
getById({ spaceId, properties, }: PluginSpaceGetByIdArgs): Promise<PluginSpaceGetByIdResult>;
|
|
6
|
+
deleteById({ spaceId, }: PluginSpaceDeleteByIdArgs): Promise<PluginSpaceDeleteByIdResult>;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=space.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"space.d.ts","sourceRoot":"","sources":["../../../src/api/entity/space.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,gCAAgC,EAChC,kCAAkC,EAClC,yBAAyB,EACzB,2BAA2B,EAC3B,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,wBAAwB,CAAA;AAG/B,qBAAa,cAAe,SAAQ,cAAc;;IAKnC,iBAAiB,CAAC,EAC7B,QAAQ,EACR,UAAU,GACX,EAAE,gCAAgC,GAAG,OAAO,CAAC,kCAAkC,CAAC;IAWpE,OAAO,CAAC,EACnB,OAAO,EACP,UAAU,GACX,EAAE,sBAAsB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAWhD,UAAU,CAAC,EACtB,OAAO,GACR,EAAE,yBAAyB,GAAG,OAAO,CAAC,2BAA2B,CAAC;CASpE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ClientEntityApi } from "./entity";
|
|
2
|
+
import { ClientToolsApi } from "./tools";
|
|
3
|
+
import { PluginApi } from "@snaptrude/plugin-core";
|
|
4
|
+
export declare class ClientPluginApi extends PluginApi {
|
|
5
|
+
private static instance;
|
|
6
|
+
tools: ClientToolsApi;
|
|
7
|
+
entity: ClientEntityApi;
|
|
8
|
+
private constructor();
|
|
9
|
+
static getInstance(): ClientPluginApi;
|
|
10
|
+
}
|
|
11
|
+
export * from "./entity";
|
|
12
|
+
export * from "./tools";
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/api/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAElD,qBAAa,eAAgB,SAAQ,SAAS;IAC5C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAiB;IAEjC,KAAK,EAAE,cAAc,CAAA;IACrB,MAAM,EAAE,eAAe,CAAA;IAE9B,OAAO;IAMP,MAAM,CAAC,WAAW,IAAI,eAAe;CAMtC;AAED,cAAc,UAAU,CAAA;AACxB,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PluginToolsApi } from "@snaptrude/plugin-core";
|
|
2
|
+
import { ClientSelectionApi } from "./selection";
|
|
3
|
+
import { ClientTransformApi } from "./transform";
|
|
4
|
+
export declare class ClientToolsApi extends PluginToolsApi {
|
|
5
|
+
selection: ClientSelectionApi;
|
|
6
|
+
transform: ClientTransformApi;
|
|
7
|
+
constructor();
|
|
8
|
+
}
|
|
9
|
+
export * from "./selection";
|
|
10
|
+
export * from "./transform";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/api/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAEhD,qBAAa,cAAe,SAAQ,cAAc;IACzC,SAAS,EAAE,kBAAkB,CAAA;IAC7B,SAAS,EAAE,kBAAkB,CAAA;;CAOrC;AAED,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selection.d.ts","sourceRoot":"","sources":["../../../src/api/tools/selection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAA;AAGrF,qBAAa,kBAAmB,SAAQ,kBAAkB;;IAK3C,GAAG,IAAI,OAAO,CAAC,wBAAwB,CAAC;CAMtD"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { PluginTransformApi, PluginMoveArgs, PluginRotateArgs } from "@snaptrude/plugin-core";
|
|
2
|
+
export declare class ClientTransformApi extends PluginTransformApi {
|
|
3
|
+
constructor();
|
|
4
|
+
move({ componentIds, displacement, }: PluginMoveArgs): Promise<void>;
|
|
5
|
+
rotate({ componentIds, angle, axis, pivot, }: PluginRotateArgs): Promise<void>;
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../src/api/tools/transform.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EACjB,MAAM,wBAAwB,CAAA;AAG/B,qBAAa,kBAAmB,SAAQ,kBAAkB;;IAK3C,IAAI,CAAC,EAChB,YAAY,EACZ,YAAY,GACb,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAWpB,MAAM,CAAC,EAClB,YAAY,EACZ,KAAK,EACL,IAAI,EACJ,KAAK,GACN,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;CAYpC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as Comlink from "comlink";
|
|
2
|
+
import type { PluginApiMethod, PluginApiCallPayload, PluginApiCallResult } from "@snaptrude/plugin-core";
|
|
3
|
+
export interface HostApi {
|
|
4
|
+
call<M extends PluginApiMethod>(payload: PluginApiCallPayload<M>): Promise<PluginApiCallResult<M>>;
|
|
5
|
+
}
|
|
6
|
+
export declare function createHostApi(endpoint?: Comlink.Endpoint): HostApi;
|
|
7
|
+
export declare function getHostApi(): HostApi;
|
|
8
|
+
//# sourceMappingURL=host-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-api.d.ts","sourceRoot":"","sources":["../src/host-api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAClC,OAAO,KAAK,EACV,eAAe,EACf,oBAAoB,EACpB,mBAAmB,EACpB,MAAM,wBAAwB,CAAA;AAE/B,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,CAAC,SAAS,eAAe,EAC5B,OAAO,EAAE,oBAAoB,CAAC,CAAC,CAAC,GAC/B,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAA;CACnC;AAED,wBAAgB,aAAa,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,QAAQ,GAAG,OAAO,CAIlE;AAID,wBAAgB,UAAU,IAAI,OAAO,CAKpC"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
ClientEntityApi: () => ClientEntityApi,
|
|
34
|
+
ClientPluginApi: () => ClientPluginApi,
|
|
35
|
+
ClientSelectionApi: () => ClientSelectionApi,
|
|
36
|
+
ClientSpaceApi: () => ClientSpaceApi,
|
|
37
|
+
ClientToolsApi: () => ClientToolsApi,
|
|
38
|
+
ClientTransformApi: () => ClientTransformApi,
|
|
39
|
+
createHostApi: () => createHostApi,
|
|
40
|
+
getHostApi: () => getHostApi,
|
|
41
|
+
snaptrude: () => snaptrude
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(index_exports);
|
|
44
|
+
|
|
45
|
+
// src/api/entity/index.ts
|
|
46
|
+
var import_plugin_core2 = require("@snaptrude/plugin-core");
|
|
47
|
+
|
|
48
|
+
// src/api/entity/space.ts
|
|
49
|
+
var import_plugin_core = require("@snaptrude/plugin-core");
|
|
50
|
+
|
|
51
|
+
// src/host-api.ts
|
|
52
|
+
var Comlink = __toESM(require("comlink"), 1);
|
|
53
|
+
function createHostApi(endpoint) {
|
|
54
|
+
return Comlink.wrap(
|
|
55
|
+
endpoint ?? globalThis
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
var _instance = null;
|
|
59
|
+
function getHostApi() {
|
|
60
|
+
if (!_instance) {
|
|
61
|
+
_instance = createHostApi();
|
|
62
|
+
}
|
|
63
|
+
return _instance;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/api/entity/space.ts
|
|
67
|
+
var ClientSpaceApi = class extends import_plugin_core.PluginSpaceApi {
|
|
68
|
+
constructor() {
|
|
69
|
+
super();
|
|
70
|
+
}
|
|
71
|
+
async createRectangular({
|
|
72
|
+
position,
|
|
73
|
+
dimensions
|
|
74
|
+
}) {
|
|
75
|
+
const hostApi = getHostApi();
|
|
76
|
+
return hostApi.call({
|
|
77
|
+
method: "entity.space.createRectangular",
|
|
78
|
+
args: {
|
|
79
|
+
position,
|
|
80
|
+
dimensions
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
async getById({
|
|
85
|
+
spaceId,
|
|
86
|
+
properties
|
|
87
|
+
}) {
|
|
88
|
+
const hostApi = getHostApi();
|
|
89
|
+
return hostApi.call({
|
|
90
|
+
method: "entity.space.getById",
|
|
91
|
+
args: {
|
|
92
|
+
spaceId,
|
|
93
|
+
properties
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
async deleteById({
|
|
98
|
+
spaceId
|
|
99
|
+
}) {
|
|
100
|
+
const hostApi = getHostApi();
|
|
101
|
+
return hostApi.call({
|
|
102
|
+
method: "entity.space.deleteById",
|
|
103
|
+
args: {
|
|
104
|
+
spaceId
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
// src/api/entity/index.ts
|
|
111
|
+
var ClientEntityApi = class extends import_plugin_core2.PluginEntityApi {
|
|
112
|
+
constructor() {
|
|
113
|
+
super();
|
|
114
|
+
this.space = new ClientSpaceApi();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// src/api/tools/index.ts
|
|
119
|
+
var import_plugin_core5 = require("@snaptrude/plugin-core");
|
|
120
|
+
|
|
121
|
+
// src/api/tools/selection.ts
|
|
122
|
+
var import_plugin_core3 = require("@snaptrude/plugin-core");
|
|
123
|
+
var ClientSelectionApi = class extends import_plugin_core3.PluginSelectionApi {
|
|
124
|
+
constructor() {
|
|
125
|
+
super();
|
|
126
|
+
}
|
|
127
|
+
async get() {
|
|
128
|
+
const hostApi = getHostApi();
|
|
129
|
+
return hostApi.call({
|
|
130
|
+
method: "tools.selection.get"
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
// src/api/tools/transform.ts
|
|
136
|
+
var import_plugin_core4 = require("@snaptrude/plugin-core");
|
|
137
|
+
var ClientTransformApi = class extends import_plugin_core4.PluginTransformApi {
|
|
138
|
+
constructor() {
|
|
139
|
+
super();
|
|
140
|
+
}
|
|
141
|
+
async move({
|
|
142
|
+
componentIds,
|
|
143
|
+
displacement
|
|
144
|
+
}) {
|
|
145
|
+
const hostApi = getHostApi();
|
|
146
|
+
return hostApi.call({
|
|
147
|
+
method: "tools.transform.move",
|
|
148
|
+
args: {
|
|
149
|
+
componentIds,
|
|
150
|
+
displacement
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
async rotate({
|
|
155
|
+
componentIds,
|
|
156
|
+
angle,
|
|
157
|
+
axis,
|
|
158
|
+
pivot
|
|
159
|
+
}) {
|
|
160
|
+
const hostApi = getHostApi();
|
|
161
|
+
return hostApi.call({
|
|
162
|
+
method: "tools.transform.rotate",
|
|
163
|
+
args: {
|
|
164
|
+
componentIds,
|
|
165
|
+
angle,
|
|
166
|
+
axis,
|
|
167
|
+
pivot
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// src/api/tools/index.ts
|
|
174
|
+
var ClientToolsApi = class extends import_plugin_core5.PluginToolsApi {
|
|
175
|
+
constructor() {
|
|
176
|
+
super();
|
|
177
|
+
this.selection = new ClientSelectionApi();
|
|
178
|
+
this.transform = new ClientTransformApi();
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
// src/api/index.ts
|
|
183
|
+
var import_plugin_core6 = require("@snaptrude/plugin-core");
|
|
184
|
+
var ClientPluginApi = class _ClientPluginApi extends import_plugin_core6.PluginApi {
|
|
185
|
+
constructor() {
|
|
186
|
+
super();
|
|
187
|
+
this.tools = new ClientToolsApi();
|
|
188
|
+
this.entity = new ClientEntityApi();
|
|
189
|
+
}
|
|
190
|
+
static getInstance() {
|
|
191
|
+
if (!_ClientPluginApi.instance) {
|
|
192
|
+
_ClientPluginApi.instance = new _ClientPluginApi();
|
|
193
|
+
}
|
|
194
|
+
return _ClientPluginApi.instance;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// src/index.ts
|
|
199
|
+
var snaptrude = ClientPluginApi.getInstance();
|
|
200
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
201
|
+
0 && (module.exports = {
|
|
202
|
+
ClientEntityApi,
|
|
203
|
+
ClientPluginApi,
|
|
204
|
+
ClientSelectionApi,
|
|
205
|
+
ClientSpaceApi,
|
|
206
|
+
ClientToolsApi,
|
|
207
|
+
ClientTransformApi,
|
|
208
|
+
createHostApi,
|
|
209
|
+
getHostApi,
|
|
210
|
+
snaptrude
|
|
211
|
+
});
|
|
212
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/api/entity/index.ts","../src/api/entity/space.ts","../src/host-api.ts","../src/api/tools/index.ts","../src/api/tools/selection.ts","../src/api/tools/transform.ts","../src/api/index.ts"],"sourcesContent":["import { ClientPluginApi } from \"./api\"\n\nexport * from \"./api\"\nexport * from \"./host-api\"\n\n/**\n * The Snaptrude plugin client API.\n *\n * The main entry point for plugins to interact with the Snaptrude platform.\n */\nexport const snaptrude = ClientPluginApi.getInstance()\n","import { PluginEntityApi } from \"@snaptrude/plugin-core\"\nimport { ClientSpaceApi } from \"./space\"\n\nexport class ClientEntityApi extends PluginEntityApi {\n public space: ClientSpaceApi\n\n constructor() {\n super()\n this.space = new ClientSpaceApi()\n }\n}\n\nexport * from \"./space\"\n","import {\n PluginSpaceApi,\n PluginSpaceCreateRectangularArgs,\n PluginSpaceCreateRectangularResult,\n PluginSpaceDeleteByIdArgs,\n PluginSpaceDeleteByIdResult,\n PluginSpaceGetByIdArgs,\n PluginSpaceGetByIdResult,\n} from \"@snaptrude/plugin-core\"\nimport { getHostApi } from \"../../host-api\"\n\nexport class ClientSpaceApi extends PluginSpaceApi {\n constructor() {\n super()\n }\n\n public async createRectangular({\n position,\n dimensions,\n }: PluginSpaceCreateRectangularArgs): Promise<PluginSpaceCreateRectangularResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.space.createRectangular\",\n args: {\n position,\n dimensions,\n },\n })\n }\n\n public async getById({\n spaceId,\n properties,\n }: PluginSpaceGetByIdArgs): Promise<PluginSpaceGetByIdResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.space.getById\",\n args: {\n spaceId,\n properties,\n },\n })\n }\n\n public async deleteById({\n spaceId,\n }: PluginSpaceDeleteByIdArgs): Promise<PluginSpaceDeleteByIdResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.space.deleteById\",\n args: {\n spaceId,\n },\n })\n }\n}\n","import * as Comlink from \"comlink\"\nimport type {\n PluginApiMethod,\n PluginApiCallPayload,\n PluginApiCallResult,\n} from \"@snaptrude/plugin-core\"\n\nexport interface HostApi {\n call<M extends PluginApiMethod>(\n payload: PluginApiCallPayload<M>\n ): Promise<PluginApiCallResult<M>>\n}\n\nexport function createHostApi(endpoint?: Comlink.Endpoint): HostApi {\n return Comlink.wrap<HostApi>(\n endpoint ?? (globalThis as unknown as Comlink.Endpoint)\n ) as unknown as HostApi\n}\n\nlet _instance: HostApi | null = null\n\nexport function getHostApi(): HostApi {\n if (!_instance) {\n _instance = createHostApi()\n }\n return _instance\n}\n","import { PluginToolsApi } from \"@snaptrude/plugin-core\"\nimport { ClientSelectionApi } from \"./selection\"\nimport { ClientTransformApi } from \"./transform\"\n\nexport class ClientToolsApi extends PluginToolsApi {\n public selection: ClientSelectionApi\n public transform: ClientTransformApi\n\n constructor() {\n super()\n this.selection = new ClientSelectionApi()\n this.transform = new ClientTransformApi()\n }\n}\n\nexport * from \"./selection\"\nexport * from \"./transform\"\n","import { PluginSelectionApi, PluginSelectionGetResult } from \"@snaptrude/plugin-core\"\nimport { getHostApi } from \"../../host-api\"\n\nexport class ClientSelectionApi extends PluginSelectionApi {\n constructor() {\n super()\n }\n\n public async get(): Promise<PluginSelectionGetResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"tools.selection.get\",\n })\n }\n}\n","import {\n PluginTransformApi,\n PluginMoveArgs,\n PluginRotateArgs,\n} from \"@snaptrude/plugin-core\"\nimport { getHostApi } from \"../../host-api\"\n\nexport class ClientTransformApi extends PluginTransformApi {\n constructor() {\n super()\n }\n\n public async move({\n componentIds,\n displacement,\n }: PluginMoveArgs): Promise<void> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"tools.transform.move\",\n args: {\n componentIds,\n displacement,\n },\n })\n }\n\n public async rotate({\n componentIds,\n angle,\n axis,\n pivot,\n }: PluginRotateArgs): Promise<void> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"tools.transform.rotate\",\n args: {\n componentIds,\n angle,\n axis,\n pivot,\n },\n })\n }\n}\n","import { ClientEntityApi } from \"./entity\"\nimport { ClientToolsApi } from \"./tools\"\nimport { PluginApi } from \"@snaptrude/plugin-core\"\n\nexport class ClientPluginApi extends PluginApi {\n private static instance: ClientPluginApi\n\n public tools: ClientToolsApi\n public entity: ClientEntityApi\n\n private constructor() {\n super()\n this.tools = new ClientToolsApi()\n this.entity = new ClientEntityApi()\n }\n\n static getInstance(): ClientPluginApi {\n if (!ClientPluginApi.instance) {\n ClientPluginApi.instance = new ClientPluginApi()\n }\n return ClientPluginApi.instance\n }\n}\n\nexport * from \"./entity\"\nexport * from \"./tools\"\n"],"mappings":"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","names":["import_plugin_core","import_plugin_core","import_plugin_core","import_plugin_core","import_plugin_core"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ClientPluginApi } from "./api";
|
|
2
|
+
export * from "./api";
|
|
3
|
+
export * from "./host-api";
|
|
4
|
+
/**
|
|
5
|
+
* The Snaptrude plugin client API.
|
|
6
|
+
*
|
|
7
|
+
* The main entry point for plugins to interact with the Snaptrude platform.
|
|
8
|
+
*/
|
|
9
|
+
export declare const snaptrude: ClientPluginApi;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAA;AAEvC,cAAc,OAAO,CAAA;AACrB,cAAc,YAAY,CAAA;AAE1B;;;;GAIG;AACH,eAAO,MAAM,SAAS,iBAAgC,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// src/api/entity/index.ts
|
|
2
|
+
import { PluginEntityApi } from "@snaptrude/plugin-core";
|
|
3
|
+
|
|
4
|
+
// src/api/entity/space.ts
|
|
5
|
+
import {
|
|
6
|
+
PluginSpaceApi
|
|
7
|
+
} from "@snaptrude/plugin-core";
|
|
8
|
+
|
|
9
|
+
// src/host-api.ts
|
|
10
|
+
import * as Comlink from "comlink";
|
|
11
|
+
function createHostApi(endpoint) {
|
|
12
|
+
return Comlink.wrap(
|
|
13
|
+
endpoint ?? globalThis
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
var _instance = null;
|
|
17
|
+
function getHostApi() {
|
|
18
|
+
if (!_instance) {
|
|
19
|
+
_instance = createHostApi();
|
|
20
|
+
}
|
|
21
|
+
return _instance;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/api/entity/space.ts
|
|
25
|
+
var ClientSpaceApi = class extends PluginSpaceApi {
|
|
26
|
+
constructor() {
|
|
27
|
+
super();
|
|
28
|
+
}
|
|
29
|
+
async createRectangular({
|
|
30
|
+
position,
|
|
31
|
+
dimensions
|
|
32
|
+
}) {
|
|
33
|
+
const hostApi = getHostApi();
|
|
34
|
+
return hostApi.call({
|
|
35
|
+
method: "entity.space.createRectangular",
|
|
36
|
+
args: {
|
|
37
|
+
position,
|
|
38
|
+
dimensions
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async getById({
|
|
43
|
+
spaceId,
|
|
44
|
+
properties
|
|
45
|
+
}) {
|
|
46
|
+
const hostApi = getHostApi();
|
|
47
|
+
return hostApi.call({
|
|
48
|
+
method: "entity.space.getById",
|
|
49
|
+
args: {
|
|
50
|
+
spaceId,
|
|
51
|
+
properties
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async deleteById({
|
|
56
|
+
spaceId
|
|
57
|
+
}) {
|
|
58
|
+
const hostApi = getHostApi();
|
|
59
|
+
return hostApi.call({
|
|
60
|
+
method: "entity.space.deleteById",
|
|
61
|
+
args: {
|
|
62
|
+
spaceId
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// src/api/entity/index.ts
|
|
69
|
+
var ClientEntityApi = class extends PluginEntityApi {
|
|
70
|
+
constructor() {
|
|
71
|
+
super();
|
|
72
|
+
this.space = new ClientSpaceApi();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/api/tools/index.ts
|
|
77
|
+
import { PluginToolsApi } from "@snaptrude/plugin-core";
|
|
78
|
+
|
|
79
|
+
// src/api/tools/selection.ts
|
|
80
|
+
import { PluginSelectionApi } from "@snaptrude/plugin-core";
|
|
81
|
+
var ClientSelectionApi = class extends PluginSelectionApi {
|
|
82
|
+
constructor() {
|
|
83
|
+
super();
|
|
84
|
+
}
|
|
85
|
+
async get() {
|
|
86
|
+
const hostApi = getHostApi();
|
|
87
|
+
return hostApi.call({
|
|
88
|
+
method: "tools.selection.get"
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// src/api/tools/transform.ts
|
|
94
|
+
import {
|
|
95
|
+
PluginTransformApi
|
|
96
|
+
} from "@snaptrude/plugin-core";
|
|
97
|
+
var ClientTransformApi = class extends PluginTransformApi {
|
|
98
|
+
constructor() {
|
|
99
|
+
super();
|
|
100
|
+
}
|
|
101
|
+
async move({
|
|
102
|
+
componentIds,
|
|
103
|
+
displacement
|
|
104
|
+
}) {
|
|
105
|
+
const hostApi = getHostApi();
|
|
106
|
+
return hostApi.call({
|
|
107
|
+
method: "tools.transform.move",
|
|
108
|
+
args: {
|
|
109
|
+
componentIds,
|
|
110
|
+
displacement
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
async rotate({
|
|
115
|
+
componentIds,
|
|
116
|
+
angle,
|
|
117
|
+
axis,
|
|
118
|
+
pivot
|
|
119
|
+
}) {
|
|
120
|
+
const hostApi = getHostApi();
|
|
121
|
+
return hostApi.call({
|
|
122
|
+
method: "tools.transform.rotate",
|
|
123
|
+
args: {
|
|
124
|
+
componentIds,
|
|
125
|
+
angle,
|
|
126
|
+
axis,
|
|
127
|
+
pivot
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
// src/api/tools/index.ts
|
|
134
|
+
var ClientToolsApi = class extends PluginToolsApi {
|
|
135
|
+
constructor() {
|
|
136
|
+
super();
|
|
137
|
+
this.selection = new ClientSelectionApi();
|
|
138
|
+
this.transform = new ClientTransformApi();
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// src/api/index.ts
|
|
143
|
+
import { PluginApi } from "@snaptrude/plugin-core";
|
|
144
|
+
var ClientPluginApi = class _ClientPluginApi extends PluginApi {
|
|
145
|
+
constructor() {
|
|
146
|
+
super();
|
|
147
|
+
this.tools = new ClientToolsApi();
|
|
148
|
+
this.entity = new ClientEntityApi();
|
|
149
|
+
}
|
|
150
|
+
static getInstance() {
|
|
151
|
+
if (!_ClientPluginApi.instance) {
|
|
152
|
+
_ClientPluginApi.instance = new _ClientPluginApi();
|
|
153
|
+
}
|
|
154
|
+
return _ClientPluginApi.instance;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// src/index.ts
|
|
159
|
+
var snaptrude = ClientPluginApi.getInstance();
|
|
160
|
+
export {
|
|
161
|
+
ClientEntityApi,
|
|
162
|
+
ClientPluginApi,
|
|
163
|
+
ClientSelectionApi,
|
|
164
|
+
ClientSpaceApi,
|
|
165
|
+
ClientToolsApi,
|
|
166
|
+
ClientTransformApi,
|
|
167
|
+
createHostApi,
|
|
168
|
+
getHostApi,
|
|
169
|
+
snaptrude
|
|
170
|
+
};
|
|
171
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/api/entity/index.ts","../src/api/entity/space.ts","../src/host-api.ts","../src/api/tools/index.ts","../src/api/tools/selection.ts","../src/api/tools/transform.ts","../src/api/index.ts","../src/index.ts"],"sourcesContent":["import { PluginEntityApi } from \"@snaptrude/plugin-core\"\nimport { ClientSpaceApi } from \"./space\"\n\nexport class ClientEntityApi extends PluginEntityApi {\n public space: ClientSpaceApi\n\n constructor() {\n super()\n this.space = new ClientSpaceApi()\n }\n}\n\nexport * from \"./space\"\n","import {\n PluginSpaceApi,\n PluginSpaceCreateRectangularArgs,\n PluginSpaceCreateRectangularResult,\n PluginSpaceDeleteByIdArgs,\n PluginSpaceDeleteByIdResult,\n PluginSpaceGetByIdArgs,\n PluginSpaceGetByIdResult,\n} from \"@snaptrude/plugin-core\"\nimport { getHostApi } from \"../../host-api\"\n\nexport class ClientSpaceApi extends PluginSpaceApi {\n constructor() {\n super()\n }\n\n public async createRectangular({\n position,\n dimensions,\n }: PluginSpaceCreateRectangularArgs): Promise<PluginSpaceCreateRectangularResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.space.createRectangular\",\n args: {\n position,\n dimensions,\n },\n })\n }\n\n public async getById({\n spaceId,\n properties,\n }: PluginSpaceGetByIdArgs): Promise<PluginSpaceGetByIdResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.space.getById\",\n args: {\n spaceId,\n properties,\n },\n })\n }\n\n public async deleteById({\n spaceId,\n }: PluginSpaceDeleteByIdArgs): Promise<PluginSpaceDeleteByIdResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"entity.space.deleteById\",\n args: {\n spaceId,\n },\n })\n }\n}\n","import * as Comlink from \"comlink\"\nimport type {\n PluginApiMethod,\n PluginApiCallPayload,\n PluginApiCallResult,\n} from \"@snaptrude/plugin-core\"\n\nexport interface HostApi {\n call<M extends PluginApiMethod>(\n payload: PluginApiCallPayload<M>\n ): Promise<PluginApiCallResult<M>>\n}\n\nexport function createHostApi(endpoint?: Comlink.Endpoint): HostApi {\n return Comlink.wrap<HostApi>(\n endpoint ?? (globalThis as unknown as Comlink.Endpoint)\n ) as unknown as HostApi\n}\n\nlet _instance: HostApi | null = null\n\nexport function getHostApi(): HostApi {\n if (!_instance) {\n _instance = createHostApi()\n }\n return _instance\n}\n","import { PluginToolsApi } from \"@snaptrude/plugin-core\"\nimport { ClientSelectionApi } from \"./selection\"\nimport { ClientTransformApi } from \"./transform\"\n\nexport class ClientToolsApi extends PluginToolsApi {\n public selection: ClientSelectionApi\n public transform: ClientTransformApi\n\n constructor() {\n super()\n this.selection = new ClientSelectionApi()\n this.transform = new ClientTransformApi()\n }\n}\n\nexport * from \"./selection\"\nexport * from \"./transform\"\n","import { PluginSelectionApi, PluginSelectionGetResult } from \"@snaptrude/plugin-core\"\nimport { getHostApi } from \"../../host-api\"\n\nexport class ClientSelectionApi extends PluginSelectionApi {\n constructor() {\n super()\n }\n\n public async get(): Promise<PluginSelectionGetResult> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"tools.selection.get\",\n })\n }\n}\n","import {\n PluginTransformApi,\n PluginMoveArgs,\n PluginRotateArgs,\n} from \"@snaptrude/plugin-core\"\nimport { getHostApi } from \"../../host-api\"\n\nexport class ClientTransformApi extends PluginTransformApi {\n constructor() {\n super()\n }\n\n public async move({\n componentIds,\n displacement,\n }: PluginMoveArgs): Promise<void> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"tools.transform.move\",\n args: {\n componentIds,\n displacement,\n },\n })\n }\n\n public async rotate({\n componentIds,\n angle,\n axis,\n pivot,\n }: PluginRotateArgs): Promise<void> {\n const hostApi = getHostApi()\n return hostApi.call({\n method: \"tools.transform.rotate\",\n args: {\n componentIds,\n angle,\n axis,\n pivot,\n },\n })\n }\n}\n","import { ClientEntityApi } from \"./entity\"\nimport { ClientToolsApi } from \"./tools\"\nimport { PluginApi } from \"@snaptrude/plugin-core\"\n\nexport class ClientPluginApi extends PluginApi {\n private static instance: ClientPluginApi\n\n public tools: ClientToolsApi\n public entity: ClientEntityApi\n\n private constructor() {\n super()\n this.tools = new ClientToolsApi()\n this.entity = new ClientEntityApi()\n }\n\n static getInstance(): ClientPluginApi {\n if (!ClientPluginApi.instance) {\n ClientPluginApi.instance = new ClientPluginApi()\n }\n return ClientPluginApi.instance\n }\n}\n\nexport * from \"./entity\"\nexport * from \"./tools\"\n","import { ClientPluginApi } from \"./api\"\n\nexport * from \"./api\"\nexport * from \"./host-api\"\n\n/**\n * The Snaptrude plugin client API.\n *\n * The main entry point for plugins to interact with the Snaptrude platform.\n */\nexport const snaptrude = ClientPluginApi.getInstance()\n"],"mappings":"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","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@snaptrude/plugin-client",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"require": "./dist/index.cjs",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"comlink": "^4.4.2",
|
|
21
|
+
"@snaptrude/plugin-core": "0.0.1"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"tsup": "^8.5.1",
|
|
25
|
+
"typescript": "^5.5.4"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"check-types": "tsc --noEmit",
|
|
29
|
+
"build": "tsup",
|
|
30
|
+
"dev": "tsup --watch",
|
|
31
|
+
"clean-dist": "rm -rf dist"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PluginEntityApi } from "@snaptrude/plugin-core"
|
|
2
|
+
import { ClientSpaceApi } from "./space"
|
|
3
|
+
|
|
4
|
+
export class ClientEntityApi extends PluginEntityApi {
|
|
5
|
+
public space: ClientSpaceApi
|
|
6
|
+
|
|
7
|
+
constructor() {
|
|
8
|
+
super()
|
|
9
|
+
this.space = new ClientSpaceApi()
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export * from "./space"
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PluginSpaceApi,
|
|
3
|
+
PluginSpaceCreateRectangularArgs,
|
|
4
|
+
PluginSpaceCreateRectangularResult,
|
|
5
|
+
PluginSpaceDeleteByIdArgs,
|
|
6
|
+
PluginSpaceDeleteByIdResult,
|
|
7
|
+
PluginSpaceGetByIdArgs,
|
|
8
|
+
PluginSpaceGetByIdResult,
|
|
9
|
+
} from "@snaptrude/plugin-core"
|
|
10
|
+
import { getHostApi } from "../../host-api"
|
|
11
|
+
|
|
12
|
+
export class ClientSpaceApi extends PluginSpaceApi {
|
|
13
|
+
constructor() {
|
|
14
|
+
super()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
public async createRectangular({
|
|
18
|
+
position,
|
|
19
|
+
dimensions,
|
|
20
|
+
}: PluginSpaceCreateRectangularArgs): Promise<PluginSpaceCreateRectangularResult> {
|
|
21
|
+
const hostApi = getHostApi()
|
|
22
|
+
return hostApi.call({
|
|
23
|
+
method: "entity.space.createRectangular",
|
|
24
|
+
args: {
|
|
25
|
+
position,
|
|
26
|
+
dimensions,
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public async getById({
|
|
32
|
+
spaceId,
|
|
33
|
+
properties,
|
|
34
|
+
}: PluginSpaceGetByIdArgs): Promise<PluginSpaceGetByIdResult> {
|
|
35
|
+
const hostApi = getHostApi()
|
|
36
|
+
return hostApi.call({
|
|
37
|
+
method: "entity.space.getById",
|
|
38
|
+
args: {
|
|
39
|
+
spaceId,
|
|
40
|
+
properties,
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public async deleteById({
|
|
46
|
+
spaceId,
|
|
47
|
+
}: PluginSpaceDeleteByIdArgs): Promise<PluginSpaceDeleteByIdResult> {
|
|
48
|
+
const hostApi = getHostApi()
|
|
49
|
+
return hostApi.call({
|
|
50
|
+
method: "entity.space.deleteById",
|
|
51
|
+
args: {
|
|
52
|
+
spaceId,
|
|
53
|
+
},
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
}
|
package/src/api/index.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ClientEntityApi } from "./entity"
|
|
2
|
+
import { ClientToolsApi } from "./tools"
|
|
3
|
+
import { PluginApi } from "@snaptrude/plugin-core"
|
|
4
|
+
|
|
5
|
+
export class ClientPluginApi extends PluginApi {
|
|
6
|
+
private static instance: ClientPluginApi
|
|
7
|
+
|
|
8
|
+
public tools: ClientToolsApi
|
|
9
|
+
public entity: ClientEntityApi
|
|
10
|
+
|
|
11
|
+
private constructor() {
|
|
12
|
+
super()
|
|
13
|
+
this.tools = new ClientToolsApi()
|
|
14
|
+
this.entity = new ClientEntityApi()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static getInstance(): ClientPluginApi {
|
|
18
|
+
if (!ClientPluginApi.instance) {
|
|
19
|
+
ClientPluginApi.instance = new ClientPluginApi()
|
|
20
|
+
}
|
|
21
|
+
return ClientPluginApi.instance
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export * from "./entity"
|
|
26
|
+
export * from "./tools"
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PluginToolsApi } from "@snaptrude/plugin-core"
|
|
2
|
+
import { ClientSelectionApi } from "./selection"
|
|
3
|
+
import { ClientTransformApi } from "./transform"
|
|
4
|
+
|
|
5
|
+
export class ClientToolsApi extends PluginToolsApi {
|
|
6
|
+
public selection: ClientSelectionApi
|
|
7
|
+
public transform: ClientTransformApi
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
super()
|
|
11
|
+
this.selection = new ClientSelectionApi()
|
|
12
|
+
this.transform = new ClientTransformApi()
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export * from "./selection"
|
|
17
|
+
export * from "./transform"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PluginSelectionApi, PluginSelectionGetResult } from "@snaptrude/plugin-core"
|
|
2
|
+
import { getHostApi } from "../../host-api"
|
|
3
|
+
|
|
4
|
+
export class ClientSelectionApi extends PluginSelectionApi {
|
|
5
|
+
constructor() {
|
|
6
|
+
super()
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
public async get(): Promise<PluginSelectionGetResult> {
|
|
10
|
+
const hostApi = getHostApi()
|
|
11
|
+
return hostApi.call({
|
|
12
|
+
method: "tools.selection.get",
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PluginTransformApi,
|
|
3
|
+
PluginMoveArgs,
|
|
4
|
+
PluginRotateArgs,
|
|
5
|
+
} from "@snaptrude/plugin-core"
|
|
6
|
+
import { getHostApi } from "../../host-api"
|
|
7
|
+
|
|
8
|
+
export class ClientTransformApi extends PluginTransformApi {
|
|
9
|
+
constructor() {
|
|
10
|
+
super()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
public async move({
|
|
14
|
+
componentIds,
|
|
15
|
+
displacement,
|
|
16
|
+
}: PluginMoveArgs): Promise<void> {
|
|
17
|
+
const hostApi = getHostApi()
|
|
18
|
+
return hostApi.call({
|
|
19
|
+
method: "tools.transform.move",
|
|
20
|
+
args: {
|
|
21
|
+
componentIds,
|
|
22
|
+
displacement,
|
|
23
|
+
},
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public async rotate({
|
|
28
|
+
componentIds,
|
|
29
|
+
angle,
|
|
30
|
+
axis,
|
|
31
|
+
pivot,
|
|
32
|
+
}: PluginRotateArgs): Promise<void> {
|
|
33
|
+
const hostApi = getHostApi()
|
|
34
|
+
return hostApi.call({
|
|
35
|
+
method: "tools.transform.rotate",
|
|
36
|
+
args: {
|
|
37
|
+
componentIds,
|
|
38
|
+
angle,
|
|
39
|
+
axis,
|
|
40
|
+
pivot,
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
}
|
package/src/host-api.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as Comlink from "comlink"
|
|
2
|
+
import type {
|
|
3
|
+
PluginApiMethod,
|
|
4
|
+
PluginApiCallPayload,
|
|
5
|
+
PluginApiCallResult,
|
|
6
|
+
} from "@snaptrude/plugin-core"
|
|
7
|
+
|
|
8
|
+
export interface HostApi {
|
|
9
|
+
call<M extends PluginApiMethod>(
|
|
10
|
+
payload: PluginApiCallPayload<M>
|
|
11
|
+
): Promise<PluginApiCallResult<M>>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function createHostApi(endpoint?: Comlink.Endpoint): HostApi {
|
|
15
|
+
return Comlink.wrap<HostApi>(
|
|
16
|
+
endpoint ?? (globalThis as unknown as Comlink.Endpoint)
|
|
17
|
+
) as unknown as HostApi
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let _instance: HostApi | null = null
|
|
21
|
+
|
|
22
|
+
export function getHostApi(): HostApi {
|
|
23
|
+
if (!_instance) {
|
|
24
|
+
_instance = createHostApi()
|
|
25
|
+
}
|
|
26
|
+
return _instance
|
|
27
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ClientPluginApi } from "./api"
|
|
2
|
+
|
|
3
|
+
export * from "./api"
|
|
4
|
+
export * from "./host-api"
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The Snaptrude plugin client API.
|
|
8
|
+
*
|
|
9
|
+
* The main entry point for plugins to interact with the Snaptrude platform.
|
|
10
|
+
*/
|
|
11
|
+
export const snaptrude = ClientPluginApi.getInstance()
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "ES2020",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"lib": ["ES2020"],
|
|
7
|
+
"strict": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"emitDeclarationOnly": true,
|
|
11
|
+
"declaration": true,
|
|
12
|
+
"declarationMap": true,
|
|
13
|
+
"outDir": "dist",
|
|
14
|
+
},
|
|
15
|
+
"include": ["src/**/*.ts"],
|
|
16
|
+
}
|
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineConfig } from "tsup"
|
|
2
|
+
|
|
3
|
+
export default defineConfig( (options) => {
|
|
4
|
+
return {
|
|
5
|
+
entry: ["src/index.ts"],
|
|
6
|
+
format: ["cjs", "esm"],
|
|
7
|
+
dts: false,
|
|
8
|
+
sourcemap: true,
|
|
9
|
+
clean: true,
|
|
10
|
+
onSuccess: "tsc", // Run tsc to generate d.ts and d.ts.map
|
|
11
|
+
watch: options.watch,
|
|
12
|
+
}
|
|
13
|
+
})
|