lucid-extension-sdk 1.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/bin/constants.d.ts +14 -0
- package/bin/constants.js +2 -0
- package/bin/document/blockclasses/blockproxyregistry.d.ts +5 -0
- package/bin/document/blockclasses/blockproxyregistry.js +8 -0
- package/bin/document/blockclasses/erdblockproxy.d.ts +15 -0
- package/bin/document/blockclasses/erdblockproxy.js +40 -0
- package/bin/document/blockdefinition.d.ts +5 -0
- package/bin/document/blockdefinition.js +2 -0
- package/bin/document/blockproxy.d.ts +7 -0
- package/bin/document/blockproxy.js +17 -0
- package/bin/document/documentproxy.d.ts +10 -0
- package/bin/document/documentproxy.js +20 -0
- package/bin/document/elementproxy.d.ts +10 -0
- package/bin/document/elementproxy.js +30 -0
- package/bin/document/groupproxy.d.ts +9 -0
- package/bin/document/groupproxy.js +14 -0
- package/bin/document/itemproxy.d.ts +16 -0
- package/bin/document/itemproxy.js +54 -0
- package/bin/document/linedefinition.d.ts +29 -0
- package/bin/document/linedefinition.js +12 -0
- package/bin/document/lineproxy.d.ts +10 -0
- package/bin/document/lineproxy.js +40 -0
- package/bin/document/mapproxy.d.ts +16 -0
- package/bin/document/mapproxy.js +35 -0
- package/bin/document/pagedefinition.d.ts +3 -0
- package/bin/document/pagedefinition.js +2 -0
- package/bin/document/pageproxy.d.ts +20 -0
- package/bin/document/pageproxy.js +80 -0
- package/bin/editorclient.d.ts +21 -0
- package/bin/editorclient.js +100 -0
- package/bin/index.d.ts +4 -0
- package/bin/index.js +9 -0
- package/bin/math.d.ts +10 -0
- package/bin/math.js +2 -0
- package/bin/ui/menu.d.ts +26 -0
- package/bin/ui/menu.js +19 -0
- package/bin/ui/viewport.d.ts +10 -0
- package/bin/ui/viewport.js +22 -0
- package/package.json +13 -0
- package/src/constants.ts +14 -0
- package/src/document/blockclasses/blockproxyregistry.ts +12 -0
- package/src/document/blockclasses/erdblockproxy.ts +41 -0
- package/src/document/blockdefinition.ts +6 -0
- package/src/document/blockproxy.ts +17 -0
- package/src/document/documentproxy.ts +28 -0
- package/src/document/elementproxy.ts +41 -0
- package/src/document/groupproxy.ts +25 -0
- package/src/document/itemproxy.ts +58 -0
- package/src/document/linedefinition.ts +41 -0
- package/src/document/lineproxy.ts +48 -0
- package/src/document/mapproxy.ts +43 -0
- package/src/document/pagedefinition.ts +3 -0
- package/src/document/pageproxy.ts +128 -0
- package/src/editorclient.ts +109 -0
- package/src/index.ts +4 -0
- package/src/interop.d.ts +8 -0
- package/src/math.ts +2 -0
- package/src/ui/menu.ts +43 -0
- package/src/ui/viewport.ts +22 -0
- package/tsconfig.json +38 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import {ElementProxy} from './elementproxy';
|
|
2
|
+
import {MapProxy} from './mapproxy';
|
|
3
|
+
import {BlockProxy} from './blockproxy';
|
|
4
|
+
import {LineProxy} from './lineproxy';
|
|
5
|
+
import {GroupProxy} from './groupproxy';
|
|
6
|
+
import {BlockDefinition} from './blockdefinition';
|
|
7
|
+
import {
|
|
8
|
+
EndpointDefinition,
|
|
9
|
+
LineDefinition,
|
|
10
|
+
isBlockEndpointDefinition,
|
|
11
|
+
isLineEndpointDefinition,
|
|
12
|
+
} from './linedefinition';
|
|
13
|
+
|
|
14
|
+
export class PageProxy extends ElementProxy {
|
|
15
|
+
public readonly blocks = new MapProxy<string, BlockProxy>(this.client, 'lb', {id: this.id}, (id) =>
|
|
16
|
+
this.client.getBlockProxy(id),
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
public readonly lines = new MapProxy<string, LineProxy>(
|
|
20
|
+
this.client,
|
|
21
|
+
'll',
|
|
22
|
+
{id: this.id},
|
|
23
|
+
(id) => new LineProxy(id, this.client),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
public readonly groups = new MapProxy<string, GroupProxy>(
|
|
27
|
+
this.client,
|
|
28
|
+
'lg',
|
|
29
|
+
{id: this.id},
|
|
30
|
+
(id) => new GroupProxy(id, this.client),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
public readonly allBlocks = new MapProxy<string, BlockProxy>(this.client, 'lb', {id: this.id, d: true}, (id) =>
|
|
34
|
+
this.client.getBlockProxy(id),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
public readonly allLines = new MapProxy<string, LineProxy>(
|
|
38
|
+
this.client,
|
|
39
|
+
'll',
|
|
40
|
+
{id: this.id, d: true},
|
|
41
|
+
(id) => new LineProxy(id, this.client),
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
public readonly allGroups = new MapProxy<string, GroupProxy>(
|
|
45
|
+
this.client,
|
|
46
|
+
'lg',
|
|
47
|
+
{id: this.id, d: true},
|
|
48
|
+
(id) => new GroupProxy(id, this.client),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
public addBlock(def: BlockDefinition): BlockProxy {
|
|
52
|
+
const properties: Record<string, any> = {};
|
|
53
|
+
properties['BoundingBox'] = def.boundingBox;
|
|
54
|
+
|
|
55
|
+
const id: string = this.client.sendCommand('cb', {
|
|
56
|
+
'p': this.id,
|
|
57
|
+
'c': def.className,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const block = this.client.getBlockProxy(id);
|
|
61
|
+
|
|
62
|
+
for (const key in properties) {
|
|
63
|
+
block.properties.set(key, properties[key]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return block;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public addLine(def: LineDefinition): LineProxy {
|
|
70
|
+
const properties: Record<string, any> = {};
|
|
71
|
+
|
|
72
|
+
const setEndpoint = (ep: EndpointDefinition, name: string) => {
|
|
73
|
+
if (isBlockEndpointDefinition(ep)) {
|
|
74
|
+
const bb = ep.connection.getBoundingBox();
|
|
75
|
+
properties[name] = {
|
|
76
|
+
'Style': ep.style,
|
|
77
|
+
'x': bb.x + bb.w * ep.linkX,
|
|
78
|
+
'y': bb.y + bb.h * ep.linkY,
|
|
79
|
+
'Block': ep.connection.id,
|
|
80
|
+
'LinkX': ep.linkX,
|
|
81
|
+
'LinkY': ep.linkY,
|
|
82
|
+
'Inside': ep.inside,
|
|
83
|
+
'AutoLink': ep.autoLink,
|
|
84
|
+
'Padding': ep.padding,
|
|
85
|
+
};
|
|
86
|
+
} else if (isLineEndpointDefinition(ep)) {
|
|
87
|
+
properties[name] = {
|
|
88
|
+
'Style': ep.style,
|
|
89
|
+
'Line': ep.connection.id,
|
|
90
|
+
'LineP': ep.position,
|
|
91
|
+
...ep.connection.getRelativePosition(ep.position), //x,y
|
|
92
|
+
};
|
|
93
|
+
} else {
|
|
94
|
+
properties[name] = {
|
|
95
|
+
'Style': ep.style,
|
|
96
|
+
'x': ep.x,
|
|
97
|
+
'y': ep.y,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
setEndpoint(def.endpoint1, 'Endpoint1');
|
|
102
|
+
setEndpoint(def.endpoint2, 'Endpoint2');
|
|
103
|
+
|
|
104
|
+
const id = this.client.sendCommand('cl', {
|
|
105
|
+
'p': this.id,
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
const line = new LineProxy(id, this.client);
|
|
109
|
+
|
|
110
|
+
for (const key in properties) {
|
|
111
|
+
line.properties.set(key, properties[key]);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return line;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public setTitle(title: string) {
|
|
118
|
+
this.properties.set('Title', title);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public getTitle(): string {
|
|
122
|
+
return this.properties.get('Title');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public delete() {
|
|
126
|
+
this.client.sendCommand('dp', this.id);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {BlockProxy} from './document/blockproxy';
|
|
2
|
+
import {DocumentProxy} from './document/documentproxy';
|
|
3
|
+
import {ElementProxy} from './document/elementproxy';
|
|
4
|
+
import {GroupProxy} from './document/groupproxy';
|
|
5
|
+
import {LineProxy} from './document/lineproxy';
|
|
6
|
+
import {PageProxy} from './document/pageproxy';
|
|
7
|
+
import {findProxyClass} from './document/blockclasses/blockproxyregistry';
|
|
8
|
+
|
|
9
|
+
export class EditorClient {
|
|
10
|
+
private nextId = 0;
|
|
11
|
+
private readonly oneTimeCallbacks = new Map<number, (value: any) => void>();
|
|
12
|
+
private readonly actions = new Map<string, (value: any) => void>();
|
|
13
|
+
|
|
14
|
+
public killExtension() {
|
|
15
|
+
this.sendCommand('k');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public reloadExtension() {
|
|
19
|
+
this.sendCommand('r');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public download(filename: string, data: string, mime: string, base64: boolean) {
|
|
23
|
+
this.sendCommand('d', {
|
|
24
|
+
'f': filename,
|
|
25
|
+
'd': data,
|
|
26
|
+
'm': mime,
|
|
27
|
+
'b64': base64,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public showModal(title: string, width: number, height: number, content: string) {
|
|
32
|
+
this.sendCommand('sm', {
|
|
33
|
+
't': title,
|
|
34
|
+
'w': width,
|
|
35
|
+
'h': height,
|
|
36
|
+
'c': content,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public hideModal() {
|
|
41
|
+
this.sendCommand('hm');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public registerOneTimeAction(cb: (value: any) => void): number {
|
|
45
|
+
const id = this.nextId++;
|
|
46
|
+
this.oneTimeCallbacks.set(id, cb);
|
|
47
|
+
return id;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public registerAction(name: string, cb: (value: any) => void): void {
|
|
51
|
+
this.actions.set(name, cb);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public deleteAction(name: string) {
|
|
55
|
+
this.actions.delete(name);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public actionExists(name: string) {
|
|
59
|
+
return this.actions.has(name);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public sendCommand(name: string, params?: any): any {
|
|
63
|
+
return lucid.executeCommand(name, params);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public getBlockProxy(id: string): BlockProxy {
|
|
67
|
+
const className = this.sendCommand('gp', {'id': id, 'p': 'ClassName'});
|
|
68
|
+
const proxy = findProxyClass(className);
|
|
69
|
+
if (proxy) {
|
|
70
|
+
return new proxy(id, this);
|
|
71
|
+
} else {
|
|
72
|
+
return new BlockProxy(id, this);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public loadBlockClasses(classNames: string[]): Promise<undefined> {
|
|
77
|
+
return this.sendCommand('lbc', classNames);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public getElementProxy(id: string) {
|
|
81
|
+
const type: string = this.sendCommand('get', id);
|
|
82
|
+
switch (type) {
|
|
83
|
+
case 'block':
|
|
84
|
+
return this.getBlockProxy(id);
|
|
85
|
+
case 'line':
|
|
86
|
+
return new LineProxy(id, this);
|
|
87
|
+
case 'page':
|
|
88
|
+
return new PageProxy(id, this);
|
|
89
|
+
case 'document':
|
|
90
|
+
return new DocumentProxy(this);
|
|
91
|
+
case 'group':
|
|
92
|
+
return new GroupProxy(id, this);
|
|
93
|
+
default:
|
|
94
|
+
return new ElementProxy(id, this);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
constructor() {
|
|
99
|
+
lucid.listen((msg: any) => {
|
|
100
|
+
const resolver = this.oneTimeCallbacks.get(msg['id']);
|
|
101
|
+
if (resolver) {
|
|
102
|
+
resolver(msg['r']);
|
|
103
|
+
this.oneTimeCallbacks.delete(msg['id']);
|
|
104
|
+
} else {
|
|
105
|
+
this.actions.get(msg['id'])?.(msg);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
package/src/index.ts
ADDED
package/src/interop.d.ts
ADDED
package/src/math.ts
ADDED
package/src/ui/menu.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {EditorClient} from '../editorclient';
|
|
2
|
+
export const enum MenuType {
|
|
3
|
+
Main = 0,
|
|
4
|
+
Context = 1,
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface CustomMenuItem {
|
|
8
|
+
//The menu item itself
|
|
9
|
+
label: string;
|
|
10
|
+
action: string;
|
|
11
|
+
|
|
12
|
+
//Where to display it
|
|
13
|
+
menuType: MenuType;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The standard menu item to display this item after.
|
|
17
|
+
* Examples:
|
|
18
|
+
* ['file'] -> put at the top of the File menu
|
|
19
|
+
* ['file', 'duplicate'] -> put after Duplicate in the File menu
|
|
20
|
+
* ['file', 'export'] -> put at the top of the export submenu
|
|
21
|
+
*
|
|
22
|
+
* The path is interpreted up to the first invalid entry.
|
|
23
|
+
* If the resulting valid path is empty, a new top-level menu named Add-ons appears before Help and this is added
|
|
24
|
+
*/
|
|
25
|
+
path: string[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class Menu {
|
|
29
|
+
constructor(private readonly client: EditorClient) {}
|
|
30
|
+
|
|
31
|
+
public addMenuItem(item: CustomMenuItem) {
|
|
32
|
+
if (!this.client.actionExists(item.action)) {
|
|
33
|
+
throw new Error('Unregistered action: ' + item.action);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
this.client.sendCommand('ami', {
|
|
37
|
+
'l': item.label,
|
|
38
|
+
'a': item.action,
|
|
39
|
+
't': item.menuType,
|
|
40
|
+
'p': item.path,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {ItemProxy} from '../document/itemproxy';
|
|
2
|
+
import {PageProxy} from '../document/pageproxy';
|
|
3
|
+
import {EditorClient} from '../editorclient';
|
|
4
|
+
|
|
5
|
+
export class Viewport {
|
|
6
|
+
constructor(private readonly client: EditorClient) {}
|
|
7
|
+
|
|
8
|
+
public getSelectedItems(): ItemProxy[] {
|
|
9
|
+
const ids: string[] = this.client.sendCommand('gs');
|
|
10
|
+
return ids
|
|
11
|
+
.map((id) => this.client.getElementProxy(id))
|
|
12
|
+
.filter((proxy) => proxy instanceof ItemProxy) as ItemProxy[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public getCurrentPage() {
|
|
16
|
+
return new PageProxy(this.client.sendCommand('gcp'), this.client);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public setCurrentPage(page: PageProxy) {
|
|
20
|
+
this.client.sendCommand('scp', page.id);
|
|
21
|
+
}
|
|
22
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"declaration": true,
|
|
4
|
+
"emitDecoratorMetadata": true,
|
|
5
|
+
"experimentalDecorators": true,
|
|
6
|
+
"forceConsistentCasingInFileNames": true,
|
|
7
|
+
"module": "commonjs",
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"newLine": "lf",
|
|
10
|
+
"noEmitHelpers": true,
|
|
11
|
+
"noEmitOnError": false,
|
|
12
|
+
"noImplicitAny": true,
|
|
13
|
+
"noImplicitReturns": true,
|
|
14
|
+
"noImplicitThis": true,
|
|
15
|
+
"noUnusedLocals": false,
|
|
16
|
+
"pretty": true,
|
|
17
|
+
"removeComments": false,
|
|
18
|
+
"skipLibCheck": true,
|
|
19
|
+
"sourceMap": false,
|
|
20
|
+
"strictBindCallApply": true,
|
|
21
|
+
"strictFunctionTypes": true,
|
|
22
|
+
"strictNullChecks": true,
|
|
23
|
+
"strictPropertyInitialization": true,
|
|
24
|
+
"target": "ES2017",
|
|
25
|
+
"types": ["node"],
|
|
26
|
+
"lib": ["dom", "es5", "es6", "ES2016.Array.Include", "ES2017.String", "ES2018.Promise"],
|
|
27
|
+
"outDir": "bin",
|
|
28
|
+
},
|
|
29
|
+
"files":[
|
|
30
|
+
"src/interop.d.ts",
|
|
31
|
+
],
|
|
32
|
+
"include": [
|
|
33
|
+
"src/**/*"
|
|
34
|
+
],
|
|
35
|
+
"exclude": [
|
|
36
|
+
"node_modules"
|
|
37
|
+
]
|
|
38
|
+
}
|