lucid-extension-sdk 0.0.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.
- package/LICENSE +201 -0
- package/README.md +11 -0
- package/interop.d.ts +8 -0
- package/out/commandtypes.d.ts +426 -0
- package/out/commandtypes.js +2 -0
- package/out/core/checks.d.ts +93 -0
- package/out/core/checks.js +152 -0
- package/out/core/dataerrortype.d.ts +8 -0
- package/out/core/dataerrortype.js +2 -0
- package/out/core/jsonserializable.d.ts +8 -0
- package/out/core/jsonserializable.js +2 -0
- package/out/core/offsettype.d.ts +16 -0
- package/out/core/offsettype.js +30 -0
- package/out/core/serializeddataerror.d.ts +6 -0
- package/out/core/serializeddataerror.js +8 -0
- package/out/core/serializedfields.d.ts +58 -0
- package/out/core/serializedfields.js +37 -0
- package/out/core/shapedatainheritance.d.ts +16 -0
- package/out/core/shapedatainheritance.js +20 -0
- package/out/data/collectionproxy.d.ts +12 -0
- package/out/data/collectionproxy.js +24 -0
- package/out/data/dataerror.d.ts +6 -0
- package/out/data/dataerror.js +10 -0
- package/out/data/dataitemproxy.d.ts +10 -0
- package/out/data/dataitemproxy.js +17 -0
- package/out/data/dataproxy.d.ts +8 -0
- package/out/data/dataproxy.js +12 -0
- package/out/data/datasourceproxy.d.ts +10 -0
- package/out/data/datasourceproxy.js +17 -0
- package/out/document/blockclasses/blockproxyregistry.d.ts +13 -0
- package/out/document/blockclasses/blockproxyregistry.js +9 -0
- package/out/document/blockclasses/erdblockproxy.d.ts +15 -0
- package/out/document/blockclasses/erdblockproxy.js +41 -0
- package/out/document/blockdefinition.d.ts +5 -0
- package/out/document/blockdefinition.js +2 -0
- package/out/document/blockproxy.d.ts +6 -0
- package/out/document/blockproxy.js +17 -0
- package/out/document/documentproxy.d.ts +10 -0
- package/out/document/documentproxy.js +19 -0
- package/out/document/elementproxy.d.ts +13 -0
- package/out/document/elementproxy.js +36 -0
- package/out/document/groupproxy.d.ts +11 -0
- package/out/document/groupproxy.js +18 -0
- package/out/document/itemproxy.d.ts +21 -0
- package/out/document/itemproxy.js +55 -0
- package/out/document/linedefinition.d.ts +27 -0
- package/out/document/linedefinition.js +2 -0
- package/out/document/lineproxy.d.ts +25 -0
- package/out/document/lineproxy.js +110 -0
- package/out/document/mapproxy.d.ts +15 -0
- package/out/document/mapproxy.js +49 -0
- package/out/document/pagedefinition.d.ts +3 -0
- package/out/document/pagedefinition.js +2 -0
- package/out/document/pageproxy.d.ts +23 -0
- package/out/document/pageproxy.js +47 -0
- package/out/document/shapedataproxy.d.ts +12 -0
- package/out/document/shapedataproxy.js +45 -0
- package/out/editorclient.d.ts +43 -0
- package/out/editorclient.js +128 -0
- package/out/index.d.ts +7 -0
- package/out/index.js +19 -0
- package/out/math.d.ts +12 -0
- package/out/math.js +24 -0
- package/out/ui/alertmodal.d.ts +8 -0
- package/out/ui/alertmodal.js +37 -0
- package/out/ui/menu.d.ts +26 -0
- package/out/ui/menu.js +42 -0
- package/out/ui/modal.d.ts +36 -0
- package/out/ui/modal.js +69 -0
- package/out/ui/viewport.d.ts +11 -0
- package/out/ui/viewport.js +35 -0
- package/package.json +15 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { CommandArgs, CommandName, UnionToIntersection } from './commandtypes';
|
|
2
|
+
import { JsonSerializable } from './core/jsonserializable';
|
|
3
|
+
import { BlockProxy } from './document/blockproxy';
|
|
4
|
+
import { ElementProxy } from './document/elementproxy';
|
|
5
|
+
import { LineProxy } from './document/lineproxy';
|
|
6
|
+
export interface XHRRequest {
|
|
7
|
+
url: string;
|
|
8
|
+
method?: string;
|
|
9
|
+
data?: string;
|
|
10
|
+
headers?: {
|
|
11
|
+
[key: string]: string | string[];
|
|
12
|
+
};
|
|
13
|
+
timeoutMs?: number;
|
|
14
|
+
}
|
|
15
|
+
export interface XHRResponse {
|
|
16
|
+
url: string;
|
|
17
|
+
responseText: string;
|
|
18
|
+
status: number;
|
|
19
|
+
headers: {
|
|
20
|
+
[key: string]: string;
|
|
21
|
+
};
|
|
22
|
+
timeout?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare class EditorClient {
|
|
25
|
+
private nextId;
|
|
26
|
+
private readonly oneTimeCallbacks;
|
|
27
|
+
private readonly callbacks;
|
|
28
|
+
killExtension(): void;
|
|
29
|
+
reloadExtension(): void;
|
|
30
|
+
download(filename: string, data: string, mime: string, base64: boolean): void;
|
|
31
|
+
xhr(request: XHRRequest): Promise<XHRResponse>;
|
|
32
|
+
registerOneTimeAction(cb: (value: any) => JsonSerializable | void): number;
|
|
33
|
+
registerAction(name: string, cb: (value: any) => JsonSerializable | void): void;
|
|
34
|
+
deleteAction(name: string): void;
|
|
35
|
+
actionExists(name: string): boolean;
|
|
36
|
+
sendCommand<C extends CommandName>(name: C, params: UnionToIntersection<CommandArgs[C]['query']>): CommandArgs[C]['result'];
|
|
37
|
+
getBlockProxy(id: string): BlockProxy;
|
|
38
|
+
loadBlockClasses(classNames: string[]): Promise<undefined>;
|
|
39
|
+
getLineProxy(id: string): LineProxy;
|
|
40
|
+
getElementProxy(id: string): ElementProxy;
|
|
41
|
+
protected listenToEditor(): void;
|
|
42
|
+
constructor();
|
|
43
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EditorClient = void 0;
|
|
4
|
+
const blockproxyregistry_1 = require("./document/blockclasses/blockproxyregistry");
|
|
5
|
+
const blockproxy_1 = require("./document/blockproxy");
|
|
6
|
+
const documentproxy_1 = require("./document/documentproxy");
|
|
7
|
+
const elementproxy_1 = require("./document/elementproxy");
|
|
8
|
+
const groupproxy_1 = require("./document/groupproxy");
|
|
9
|
+
const lineproxy_1 = require("./document/lineproxy");
|
|
10
|
+
const pageproxy_1 = require("./document/pageproxy");
|
|
11
|
+
class EditorClient {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.nextId = 0;
|
|
14
|
+
this.oneTimeCallbacks = new Map();
|
|
15
|
+
this.callbacks = new Map();
|
|
16
|
+
this.listenToEditor();
|
|
17
|
+
}
|
|
18
|
+
killExtension() {
|
|
19
|
+
this.sendCommand("k" /* KillExtension */, undefined);
|
|
20
|
+
}
|
|
21
|
+
reloadExtension() {
|
|
22
|
+
this.sendCommand("r" /* ReloadExtension */, undefined);
|
|
23
|
+
}
|
|
24
|
+
download(filename, data, mime, base64) {
|
|
25
|
+
this.sendCommand("d" /* Download */, {
|
|
26
|
+
'f': filename,
|
|
27
|
+
'd': data,
|
|
28
|
+
'm': mime,
|
|
29
|
+
'b64': base64,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
xhr(request) {
|
|
33
|
+
return this.sendCommand("xhr" /* SendXHR */, {
|
|
34
|
+
'url': request.url,
|
|
35
|
+
'm': request.method,
|
|
36
|
+
'd': request.data,
|
|
37
|
+
'h': request.headers,
|
|
38
|
+
'ms': request.timeoutMs,
|
|
39
|
+
})
|
|
40
|
+
.then((raw) => {
|
|
41
|
+
return {
|
|
42
|
+
url: raw['url'],
|
|
43
|
+
responseText: raw['t'],
|
|
44
|
+
status: raw['s'],
|
|
45
|
+
headers: raw['h'],
|
|
46
|
+
timeout: raw['to'],
|
|
47
|
+
};
|
|
48
|
+
})
|
|
49
|
+
.catch((raw) => {
|
|
50
|
+
throw {
|
|
51
|
+
url: raw['url'],
|
|
52
|
+
responseText: raw['t'],
|
|
53
|
+
status: raw['s'],
|
|
54
|
+
headers: raw['h'],
|
|
55
|
+
timeout: raw['to'],
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
registerOneTimeAction(cb) {
|
|
60
|
+
const id = this.nextId++;
|
|
61
|
+
this.oneTimeCallbacks.set(id, cb);
|
|
62
|
+
return id;
|
|
63
|
+
}
|
|
64
|
+
registerAction(name, cb) {
|
|
65
|
+
this.callbacks.set(name, cb);
|
|
66
|
+
}
|
|
67
|
+
deleteAction(name) {
|
|
68
|
+
this.callbacks.delete(name);
|
|
69
|
+
}
|
|
70
|
+
actionExists(name) {
|
|
71
|
+
return this.callbacks.has(name);
|
|
72
|
+
}
|
|
73
|
+
//Note: UnionToIntersection here fixes the type of params required if you're passing in something that's not a single
|
|
74
|
+
//specific command name, to require the type of all possible command names you could pass in, intersected. So if you
|
|
75
|
+
//call this with a CommandName.ListBlocks|CommandName.ListLines it will work as expected but if you just pass in a
|
|
76
|
+
//CommandName, there won't be any possible params you could pass that would meet all the requirements (string & undefined & ...)
|
|
77
|
+
sendCommand(name, params) {
|
|
78
|
+
return lucid.executeCommand(name, params);
|
|
79
|
+
}
|
|
80
|
+
getBlockProxy(id) {
|
|
81
|
+
const className = this.sendCommand("gp" /* GetProperty */, { 'id': id, 'p': 'ClassName' });
|
|
82
|
+
const proxy = (0, blockproxyregistry_1.findProxyClass)(className);
|
|
83
|
+
if (proxy) {
|
|
84
|
+
return new proxy(id, this);
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
return new blockproxy_1.BlockProxy(id, this);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
loadBlockClasses(classNames) {
|
|
91
|
+
return this.sendCommand("lbc" /* LoadBlockClasses */, classNames);
|
|
92
|
+
}
|
|
93
|
+
getLineProxy(id) {
|
|
94
|
+
return new lineproxy_1.LineProxy(id, this);
|
|
95
|
+
}
|
|
96
|
+
getElementProxy(id) {
|
|
97
|
+
const type = this.sendCommand("get" /* GetElementType */, { 'id': id });
|
|
98
|
+
switch (type) {
|
|
99
|
+
case 'block':
|
|
100
|
+
return this.getBlockProxy(id);
|
|
101
|
+
case 'line':
|
|
102
|
+
return this.getLineProxy(id);
|
|
103
|
+
case 'page':
|
|
104
|
+
return new pageproxy_1.PageProxy(id, this);
|
|
105
|
+
case 'document':
|
|
106
|
+
return new documentproxy_1.DocumentProxy(this);
|
|
107
|
+
case 'group':
|
|
108
|
+
return new groupproxy_1.GroupProxy(id, this);
|
|
109
|
+
default:
|
|
110
|
+
return new elementproxy_1.ElementProxy(id, this);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
listenToEditor() {
|
|
114
|
+
lucid.listen((msg) => {
|
|
115
|
+
var _a;
|
|
116
|
+
const resolver = this.oneTimeCallbacks.get(msg['id']);
|
|
117
|
+
if (resolver) {
|
|
118
|
+
const result = resolver(msg['r']);
|
|
119
|
+
this.oneTimeCallbacks.delete(msg['id']);
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
return (_a = this.callbacks.get(msg['id'])) === null || _a === void 0 ? void 0 : _a(msg);
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
exports.EditorClient = EditorClient;
|
package/out/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { DataProxy } from './data/dataproxy';
|
|
2
|
+
export { DocumentProxy } from './document/documentproxy';
|
|
3
|
+
export { EditorClient } from './editorclient';
|
|
4
|
+
export { AlertModal } from './ui/alertmodal';
|
|
5
|
+
export { CustomMenuItem, Menu, MenuLocation, MenuType } from './ui/menu';
|
|
6
|
+
export { Modal } from './ui/modal';
|
|
7
|
+
export { Viewport } from './ui/viewport';
|
package/out/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Viewport = exports.Modal = exports.MenuType = exports.MenuLocation = exports.Menu = exports.AlertModal = exports.EditorClient = exports.DocumentProxy = exports.DataProxy = void 0;
|
|
4
|
+
var dataproxy_1 = require("./data/dataproxy");
|
|
5
|
+
Object.defineProperty(exports, "DataProxy", { enumerable: true, get: function () { return dataproxy_1.DataProxy; } });
|
|
6
|
+
var documentproxy_1 = require("./document/documentproxy");
|
|
7
|
+
Object.defineProperty(exports, "DocumentProxy", { enumerable: true, get: function () { return documentproxy_1.DocumentProxy; } });
|
|
8
|
+
var editorclient_1 = require("./editorclient");
|
|
9
|
+
Object.defineProperty(exports, "EditorClient", { enumerable: true, get: function () { return editorclient_1.EditorClient; } });
|
|
10
|
+
var alertmodal_1 = require("./ui/alertmodal");
|
|
11
|
+
Object.defineProperty(exports, "AlertModal", { enumerable: true, get: function () { return alertmodal_1.AlertModal; } });
|
|
12
|
+
var menu_1 = require("./ui/menu");
|
|
13
|
+
Object.defineProperty(exports, "Menu", { enumerable: true, get: function () { return menu_1.Menu; } });
|
|
14
|
+
Object.defineProperty(exports, "MenuLocation", { enumerable: true, get: function () { return menu_1.MenuLocation; } });
|
|
15
|
+
Object.defineProperty(exports, "MenuType", { enumerable: true, get: function () { return menu_1.MenuType; } });
|
|
16
|
+
var modal_1 = require("./ui/modal");
|
|
17
|
+
Object.defineProperty(exports, "Modal", { enumerable: true, get: function () { return modal_1.Modal; } });
|
|
18
|
+
var viewport_1 = require("./ui/viewport");
|
|
19
|
+
Object.defineProperty(exports, "Viewport", { enumerable: true, get: function () { return viewport_1.Viewport; } });
|
package/out/math.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare type Point = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
};
|
|
5
|
+
export declare type Box = {
|
|
6
|
+
x: number;
|
|
7
|
+
y: number;
|
|
8
|
+
w: number;
|
|
9
|
+
h: number;
|
|
10
|
+
};
|
|
11
|
+
export declare function combinedBoundingBox(boxes: Box[]): Box | undefined;
|
|
12
|
+
export declare function padBox(box: Box, padding: number): Box;
|
package/out/math.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.padBox = exports.combinedBoundingBox = void 0;
|
|
4
|
+
function combinedBoundingBox(boxes) {
|
|
5
|
+
if (boxes.length == 0) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
let minX = Number.MAX_VALUE;
|
|
9
|
+
let minY = Number.MAX_VALUE;
|
|
10
|
+
let maxX = -Number.MAX_VALUE;
|
|
11
|
+
let maxY = -Number.MAX_VALUE;
|
|
12
|
+
for (const box of boxes) {
|
|
13
|
+
minX = Math.min(minX, box.x);
|
|
14
|
+
maxX = Math.max(maxX, box.x + box.w);
|
|
15
|
+
minY = Math.min(minY, box.y);
|
|
16
|
+
maxY = Math.max(maxY, box.y + box.h);
|
|
17
|
+
}
|
|
18
|
+
return { x: minX, y: minY, w: maxX - minX, h: maxY - minY };
|
|
19
|
+
}
|
|
20
|
+
exports.combinedBoundingBox = combinedBoundingBox;
|
|
21
|
+
function padBox(box, padding) {
|
|
22
|
+
return { x: box.x - padding, y: box.y - padding, w: box.w + padding * 2, h: box.h + padding * 2 };
|
|
23
|
+
}
|
|
24
|
+
exports.padBox = padBox;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { EditorClient } from '../editorclient';
|
|
2
|
+
import { Modal } from './modal';
|
|
3
|
+
export declare class AlertModal extends Modal {
|
|
4
|
+
protected readonly client: EditorClient;
|
|
5
|
+
constructor(client: EditorClient, title: string, message: string);
|
|
6
|
+
protected messageFromFrame(message: any): void;
|
|
7
|
+
protected frameLoaded(): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AlertModal = void 0;
|
|
4
|
+
const modal_1 = require("./modal");
|
|
5
|
+
class AlertModal extends modal_1.Modal {
|
|
6
|
+
constructor(client, title, message) {
|
|
7
|
+
super(client, {
|
|
8
|
+
width: 300,
|
|
9
|
+
height: 200,
|
|
10
|
+
title: title,
|
|
11
|
+
content: `
|
|
12
|
+
<html>
|
|
13
|
+
<head>
|
|
14
|
+
<style type="text/css">
|
|
15
|
+
p {
|
|
16
|
+
font-family: 'Graphik LC Web', sans-serif;
|
|
17
|
+
font-size:14px;
|
|
18
|
+
text-align:center;
|
|
19
|
+
}
|
|
20
|
+
</style>
|
|
21
|
+
</head>
|
|
22
|
+
<body>
|
|
23
|
+
<p id="message"></p>
|
|
24
|
+
<script type="text/javascript">
|
|
25
|
+
var p = document.getElementById('message');
|
|
26
|
+
p.innerText = ${JSON.stringify(message)};
|
|
27
|
+
</script>
|
|
28
|
+
</body>
|
|
29
|
+
</html>
|
|
30
|
+
`,
|
|
31
|
+
});
|
|
32
|
+
this.client = client;
|
|
33
|
+
}
|
|
34
|
+
messageFromFrame(message) { }
|
|
35
|
+
frameLoaded() { }
|
|
36
|
+
}
|
|
37
|
+
exports.AlertModal = AlertModal;
|
package/out/ui/menu.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { EditorClient } from '../editorclient';
|
|
2
|
+
export declare enum MenuType {
|
|
3
|
+
Main = 1,
|
|
4
|
+
Context = 2
|
|
5
|
+
}
|
|
6
|
+
export declare enum MenuLocation {
|
|
7
|
+
Extension = 1,
|
|
8
|
+
Edit = 2,
|
|
9
|
+
View = 3,
|
|
10
|
+
Share = 4,
|
|
11
|
+
Export = 5,
|
|
12
|
+
Import = 6
|
|
13
|
+
}
|
|
14
|
+
export interface CustomMenuItem {
|
|
15
|
+
label: string;
|
|
16
|
+
action: string;
|
|
17
|
+
visibleAction?: string;
|
|
18
|
+
disabledAction?: string;
|
|
19
|
+
menuType: MenuType;
|
|
20
|
+
location?: MenuLocation;
|
|
21
|
+
}
|
|
22
|
+
export declare class Menu {
|
|
23
|
+
private readonly client;
|
|
24
|
+
constructor(client: EditorClient);
|
|
25
|
+
addMenuItem(item: CustomMenuItem): void;
|
|
26
|
+
}
|
package/out/ui/menu.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Menu = exports.MenuLocation = exports.MenuType = void 0;
|
|
4
|
+
var MenuType;
|
|
5
|
+
(function (MenuType) {
|
|
6
|
+
MenuType[MenuType["Main"] = 1] = "Main";
|
|
7
|
+
MenuType[MenuType["Context"] = 2] = "Context";
|
|
8
|
+
})(MenuType = exports.MenuType || (exports.MenuType = {}));
|
|
9
|
+
var MenuLocation;
|
|
10
|
+
(function (MenuLocation) {
|
|
11
|
+
MenuLocation[MenuLocation["Extension"] = 1] = "Extension";
|
|
12
|
+
MenuLocation[MenuLocation["Edit"] = 2] = "Edit";
|
|
13
|
+
MenuLocation[MenuLocation["View"] = 3] = "View";
|
|
14
|
+
MenuLocation[MenuLocation["Share"] = 4] = "Share";
|
|
15
|
+
MenuLocation[MenuLocation["Export"] = 5] = "Export";
|
|
16
|
+
MenuLocation[MenuLocation["Import"] = 6] = "Import";
|
|
17
|
+
})(MenuLocation = exports.MenuLocation || (exports.MenuLocation = {}));
|
|
18
|
+
class Menu {
|
|
19
|
+
constructor(client) {
|
|
20
|
+
this.client = client;
|
|
21
|
+
}
|
|
22
|
+
addMenuItem(item) {
|
|
23
|
+
if (!this.client.actionExists(item.action)) {
|
|
24
|
+
throw new Error('Unregistered action: ' + item.action);
|
|
25
|
+
}
|
|
26
|
+
if (item.visibleAction && !this.client.actionExists(item.visibleAction)) {
|
|
27
|
+
throw new Error('Unregistered action: ' + item.visibleAction);
|
|
28
|
+
}
|
|
29
|
+
if (item.disabledAction && !this.client.actionExists(item.disabledAction)) {
|
|
30
|
+
throw new Error('Unregistered action: ' + item.disabledAction);
|
|
31
|
+
}
|
|
32
|
+
this.client.sendCommand("ami" /* AddMenuItem */, {
|
|
33
|
+
'l': item.label,
|
|
34
|
+
'a': item.action,
|
|
35
|
+
'v': item.visibleAction,
|
|
36
|
+
'd': item.disabledAction,
|
|
37
|
+
't': item.menuType,
|
|
38
|
+
'loc': item.location,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.Menu = Menu;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { JsonSerializable } from '../core/jsonserializable';
|
|
2
|
+
import { EditorClient } from '../editorclient';
|
|
3
|
+
export interface ModalConfig {
|
|
4
|
+
title: string;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
content: string;
|
|
8
|
+
}
|
|
9
|
+
export declare enum ModalIncomingMessageType {
|
|
10
|
+
ModalClosed = 1,
|
|
11
|
+
PostMessageFromFrame = 2,
|
|
12
|
+
FrameLoaded = 3
|
|
13
|
+
}
|
|
14
|
+
export interface ModalIncomingMessage {
|
|
15
|
+
'id': string;
|
|
16
|
+
't': ModalIncomingMessageType;
|
|
17
|
+
'data'?: any;
|
|
18
|
+
}
|
|
19
|
+
export declare abstract class Modal {
|
|
20
|
+
protected readonly client: EditorClient;
|
|
21
|
+
private readonly config;
|
|
22
|
+
private static nextId;
|
|
23
|
+
private id;
|
|
24
|
+
private static modalMessageActionNamePrefix;
|
|
25
|
+
private messageActionName;
|
|
26
|
+
private visible;
|
|
27
|
+
constructor(client: EditorClient, config: ModalConfig);
|
|
28
|
+
static isMessageActionName(name: string): boolean;
|
|
29
|
+
private hookMessages;
|
|
30
|
+
private unhookMessages;
|
|
31
|
+
sendMessage(data: JsonSerializable): void;
|
|
32
|
+
protected abstract messageFromFrame(message: any): void;
|
|
33
|
+
protected abstract frameLoaded(): void;
|
|
34
|
+
show(): void;
|
|
35
|
+
hide(): void;
|
|
36
|
+
}
|
package/out/ui/modal.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Modal = exports.ModalIncomingMessageType = void 0;
|
|
4
|
+
var ModalIncomingMessageType;
|
|
5
|
+
(function (ModalIncomingMessageType) {
|
|
6
|
+
ModalIncomingMessageType[ModalIncomingMessageType["ModalClosed"] = 1] = "ModalClosed";
|
|
7
|
+
ModalIncomingMessageType[ModalIncomingMessageType["PostMessageFromFrame"] = 2] = "PostMessageFromFrame";
|
|
8
|
+
ModalIncomingMessageType[ModalIncomingMessageType["FrameLoaded"] = 3] = "FrameLoaded";
|
|
9
|
+
})(ModalIncomingMessageType = exports.ModalIncomingMessageType || (exports.ModalIncomingMessageType = {}));
|
|
10
|
+
class Modal {
|
|
11
|
+
constructor(client, config) {
|
|
12
|
+
this.client = client;
|
|
13
|
+
this.config = config;
|
|
14
|
+
this.id = ++Modal.nextId;
|
|
15
|
+
this.messageActionName = Modal.modalMessageActionNamePrefix + this.id;
|
|
16
|
+
this.visible = false;
|
|
17
|
+
}
|
|
18
|
+
static isMessageActionName(name) {
|
|
19
|
+
return name.startsWith(Modal.modalMessageActionNamePrefix);
|
|
20
|
+
}
|
|
21
|
+
hookMessages() {
|
|
22
|
+
this.client.registerAction(this.messageActionName, (message) => {
|
|
23
|
+
switch (message['t']) {
|
|
24
|
+
case ModalIncomingMessageType.ModalClosed:
|
|
25
|
+
this.unhookMessages();
|
|
26
|
+
this.visible = false;
|
|
27
|
+
break;
|
|
28
|
+
case ModalIncomingMessageType.PostMessageFromFrame:
|
|
29
|
+
this.messageFromFrame(message['data']);
|
|
30
|
+
break;
|
|
31
|
+
case ModalIncomingMessageType.FrameLoaded:
|
|
32
|
+
this.frameLoaded();
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
unhookMessages() {
|
|
38
|
+
this.client.deleteAction(this.messageActionName);
|
|
39
|
+
}
|
|
40
|
+
sendMessage(data) {
|
|
41
|
+
if (this.visible) {
|
|
42
|
+
this.client.sendCommand("suim" /* SendUIMessage */, {
|
|
43
|
+
'n': this.messageActionName,
|
|
44
|
+
'd': data,
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
show() {
|
|
49
|
+
if (!this.visible) {
|
|
50
|
+
this.hookMessages();
|
|
51
|
+
this.client.sendCommand("sm" /* ShowModal */, {
|
|
52
|
+
'n': this.messageActionName,
|
|
53
|
+
't': this.config.title,
|
|
54
|
+
'w': this.config.width,
|
|
55
|
+
'h': this.config.height,
|
|
56
|
+
'c': this.config.content,
|
|
57
|
+
});
|
|
58
|
+
this.visible = true;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
hide() {
|
|
62
|
+
if (this.visible) {
|
|
63
|
+
this.client.sendCommand("hm" /* HideModal */, { 'n': this.messageActionName });
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.Modal = Modal;
|
|
68
|
+
Modal.nextId = 0;
|
|
69
|
+
Modal.modalMessageActionNamePrefix = '__modal_message__';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ItemProxy } from '../document/itemproxy';
|
|
2
|
+
import { PageProxy } from '../document/pageproxy';
|
|
3
|
+
import { EditorClient } from '../editorclient';
|
|
4
|
+
export declare class Viewport {
|
|
5
|
+
private readonly client;
|
|
6
|
+
constructor(client: EditorClient);
|
|
7
|
+
getSelectedItems(deep?: boolean): ItemProxy[];
|
|
8
|
+
getCurrentPage(): PageProxy | undefined;
|
|
9
|
+
setCurrentPage(page: PageProxy): void;
|
|
10
|
+
focusCameraOnItems(items: ItemProxy[]): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Viewport = void 0;
|
|
4
|
+
const itemproxy_1 = require("../document/itemproxy");
|
|
5
|
+
const pageproxy_1 = require("../document/pageproxy");
|
|
6
|
+
const math_1 = require("../math");
|
|
7
|
+
class Viewport {
|
|
8
|
+
constructor(client) {
|
|
9
|
+
this.client = client;
|
|
10
|
+
}
|
|
11
|
+
getSelectedItems(deep) {
|
|
12
|
+
const ids = this.client.sendCommand("gs" /* GetSelection */, { 'd': deep });
|
|
13
|
+
return ids
|
|
14
|
+
.map((id) => this.client.getElementProxy(id))
|
|
15
|
+
.filter((proxy) => proxy instanceof itemproxy_1.ItemProxy);
|
|
16
|
+
}
|
|
17
|
+
getCurrentPage() {
|
|
18
|
+
const id = this.client.sendCommand("gcp" /* GetCurrentPage */, undefined);
|
|
19
|
+
return id == null ? id : new pageproxy_1.PageProxy(id, this.client);
|
|
20
|
+
}
|
|
21
|
+
setCurrentPage(page) {
|
|
22
|
+
this.client.sendCommand("scp" /* SetCurrentPage */, page.id);
|
|
23
|
+
}
|
|
24
|
+
focusCameraOnItems(items) {
|
|
25
|
+
const bb = (0, math_1.combinedBoundingBox)(items.map((e) => e.getBoundingBox()));
|
|
26
|
+
if (bb) {
|
|
27
|
+
//TODO: A reasonable max zoom level (e.g. 200%)
|
|
28
|
+
this.client.sendCommand("av" /* AnimateViewport */, {
|
|
29
|
+
'bb': (0, math_1.padBox)(bb, 80),
|
|
30
|
+
'p': items[0].getPageId(),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Viewport = Viewport;
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lucid-extension-sdk",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Utility classes for writing Lucid Software editor extensions",
|
|
5
|
+
"main": "out/index.js",
|
|
6
|
+
"types": "out/index.d.ts",
|
|
7
|
+
"author": "Lucid Software",
|
|
8
|
+
"license": "Apache-2.0",
|
|
9
|
+
"declaration": true,
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@types/node": "^16.11.11",
|
|
12
|
+
"@bazel/typescript": "2.0.1",
|
|
13
|
+
"typescript": "4.3.5"
|
|
14
|
+
}
|
|
15
|
+
}
|