lucid-extension-sdk 0.0.6 → 0.0.13
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/interop.d.ts +4 -0
- package/package.json +3 -3
- package/sdk/commandtypes.d.ts +241 -5
- package/sdk/commandtypes.js +6 -0
- package/sdk/core/data/referencekeys/serializedreferencekey.d.ts +6 -0
- package/sdk/core/data/referencekeys/serializedreferencekey.js +17 -1
- package/sdk/core/jsonserializable.d.ts +4 -0
- package/sdk/data/collectionproxy.d.ts +2 -2
- package/sdk/data/collectionproxy.js +2 -2
- package/sdk/data/datasourceproxy.d.ts +9 -3
- package/sdk/data/datasourceproxy.js +9 -3
- package/sdk/data/referencekeydefinition.d.ts +30 -2
- package/sdk/data/referencekeydefinition.js +26 -1
- package/sdk/data/referencekeyproxy.d.ts +4 -0
- package/sdk/data/referencekeyproxy.js +25 -0
- package/sdk/data/schemadefinition.d.ts +13 -0
- package/sdk/data/schemadefinition.js +13 -1
- package/sdk/document/blockclasses/blockproxyregistry.js +2 -1
- package/sdk/document/blockclasses/customblockproxy.d.ts +6 -0
- package/sdk/document/blockclasses/customblockproxy.js +24 -0
- package/sdk/document/blockdefinition.d.ts +4 -2
- package/sdk/document/blockproxy.d.ts +20 -4
- package/sdk/document/blockproxy.js +31 -4
- package/sdk/document/documentproxy.d.ts +22 -2
- package/sdk/document/documentproxy.js +33 -2
- package/sdk/document/elementproxy.d.ts +26 -18
- package/sdk/document/elementproxy.js +26 -29
- package/sdk/document/groupproxy.d.ts +1 -1
- package/sdk/document/groupproxy.js +1 -1
- package/sdk/document/itemproxy.d.ts +5 -5
- package/sdk/document/itemproxy.js +5 -5
- package/sdk/document/lineproxy.d.ts +32 -6
- package/sdk/document/lineproxy.js +52 -6
- package/sdk/document/linetextareapositioning.d.ts +31 -0
- package/sdk/document/linetextareapositioning.js +30 -0
- package/sdk/document/mapproxy.d.ts +7 -1
- package/sdk/document/mapproxy.js +8 -0
- package/sdk/document/propertystoreproxy.d.ts +21 -0
- package/sdk/document/propertystoreproxy.js +37 -0
- package/sdk/document/shapedataproxy.d.ts +5 -0
- package/sdk/document/shapedataproxy.js +5 -0
- package/sdk/editorclient.d.ts +8 -2
- package/sdk/editorclient.js +51 -9
- package/sdk/index.d.ts +1 -0
- package/sdk/index.js +1 -0
- package/sdk/ui/alertmodal.d.ts +2 -3
- package/sdk/ui/alertmodal.js +2 -3
- package/sdk/ui/iframeui.d.ts +57 -0
- package/sdk/ui/iframeui.js +82 -0
- package/sdk/ui/modal.d.ts +11 -33
- package/sdk/ui/modal.js +9 -46
- package/sdk/ui/panel.d.ts +43 -0
- package/sdk/ui/panel.js +50 -0
- package/sdk/ui/viewport.d.ts +45 -0
- package/sdk/ui/viewport.js +80 -0
package/sdk/editorclient.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EditorClient = void 0;
|
|
4
|
-
const
|
|
4
|
+
const commandtypes_1 = require("./commandtypes");
|
|
5
5
|
const blockproxyregistry_1 = require("./document/blockclasses/blockproxyregistry");
|
|
6
6
|
const blockproxy_1 = require("./document/blockproxy");
|
|
7
7
|
const documentproxy_1 = require("./document/documentproxy");
|
|
@@ -71,7 +71,37 @@ class EditorClient {
|
|
|
71
71
|
timeout: raw['to'],
|
|
72
72
|
};
|
|
73
73
|
})
|
|
74
|
-
.catch((
|
|
74
|
+
.catch((error) => {
|
|
75
|
+
const raw = (0, commandtypes_1.isRawSendXHRResponse)(error) ? error : undefined;
|
|
76
|
+
throw {
|
|
77
|
+
url: raw ? raw['url'] : '',
|
|
78
|
+
responseText: raw ? raw['t'] : 'An unknown error occurred',
|
|
79
|
+
status: raw ? raw['s'] : 0,
|
|
80
|
+
headers: raw ? raw['h'] : {},
|
|
81
|
+
timeout: raw ? raw['to'] : undefined,
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
oauthXhr(providerName, request) {
|
|
86
|
+
return this.sendCommand("oauth" /* SendOAuthRequest */, {
|
|
87
|
+
'url': request.url,
|
|
88
|
+
'm': request.method,
|
|
89
|
+
'd': request.data,
|
|
90
|
+
'h': request.headers,
|
|
91
|
+
'ms': request.timeoutMs,
|
|
92
|
+
'p': providerName,
|
|
93
|
+
})
|
|
94
|
+
.then((raw) => {
|
|
95
|
+
return {
|
|
96
|
+
url: raw['url'],
|
|
97
|
+
responseText: raw['t'],
|
|
98
|
+
status: raw['s'],
|
|
99
|
+
headers: raw['h'],
|
|
100
|
+
timeout: raw['to'],
|
|
101
|
+
};
|
|
102
|
+
})
|
|
103
|
+
.catch((error) => {
|
|
104
|
+
const raw = (0, commandtypes_1.isRawSendXHRResponse)(error) ? error : error;
|
|
75
105
|
throw {
|
|
76
106
|
url: raw['url'],
|
|
77
107
|
responseText: raw['t'],
|
|
@@ -123,7 +153,6 @@ class EditorClient {
|
|
|
123
153
|
* Execute an API command. This is the low-level API that most of this SDK wraps. It is not expected that you should
|
|
124
154
|
* ever need to use this directly.
|
|
125
155
|
*
|
|
126
|
-
* @hidden
|
|
127
156
|
* @param name name of the API command to execute
|
|
128
157
|
* @param params data to pass to the API command
|
|
129
158
|
* @returns the output of the given API command
|
|
@@ -165,7 +194,7 @@ class EditorClient {
|
|
|
165
194
|
* created.
|
|
166
195
|
*
|
|
167
196
|
* Example usage:
|
|
168
|
-
* ```
|
|
197
|
+
* ```inline:typescript
|
|
169
198
|
* const client = new EditorClient();
|
|
170
199
|
* const viewport = new Viewport(client);
|
|
171
200
|
*
|
|
@@ -234,6 +263,23 @@ class EditorClient {
|
|
|
234
263
|
getPageProxy(id) {
|
|
235
264
|
return new pageproxy_1.PageProxy(id, this);
|
|
236
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* @param id ID of the item to create a proxy for
|
|
268
|
+
* @returns the given item
|
|
269
|
+
*/
|
|
270
|
+
getItemProxy(id) {
|
|
271
|
+
const type = this.sendCommand("get" /* GetElementType */, { 'id': id });
|
|
272
|
+
switch (type) {
|
|
273
|
+
case 'block':
|
|
274
|
+
return this.getBlockProxy(id);
|
|
275
|
+
case 'line':
|
|
276
|
+
return this.getLineProxy(id);
|
|
277
|
+
case 'group':
|
|
278
|
+
return new groupproxy_1.GroupProxy(id, this);
|
|
279
|
+
default:
|
|
280
|
+
throw new Error('Element ' + id + ' is not an Item; type found is ' + type);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
237
283
|
/**
|
|
238
284
|
* @param id ID of the element to create a proxy for
|
|
239
285
|
* @returns the given element
|
|
@@ -261,11 +307,7 @@ class EditorClient {
|
|
|
261
307
|
listenToEditor() {
|
|
262
308
|
lucid.listen((msg) => {
|
|
263
309
|
var _a;
|
|
264
|
-
|
|
265
|
-
if ((0, checks_1.isPromise)(value)) {
|
|
266
|
-
return undefined;
|
|
267
|
-
}
|
|
268
|
-
return value;
|
|
310
|
+
return (_a = this.callbacks.get(msg['id'])) === null || _a === void 0 ? void 0 : _a(msg);
|
|
269
311
|
});
|
|
270
312
|
}
|
|
271
313
|
}
|
package/sdk/index.d.ts
CHANGED
package/sdk/index.js
CHANGED
|
@@ -38,4 +38,5 @@ __exportStar(require("./math"), exports);
|
|
|
38
38
|
__exportStar(require("./ui/alertmodal"), exports);
|
|
39
39
|
__exportStar(require("./ui/menu"), exports);
|
|
40
40
|
__exportStar(require("./ui/modal"), exports);
|
|
41
|
+
__exportStar(require("./ui/panel"), exports);
|
|
41
42
|
__exportStar(require("./ui/viewport"), exports);
|
package/sdk/ui/alertmodal.d.ts
CHANGED
|
@@ -2,10 +2,9 @@ import { EditorClient } from '../editorclient';
|
|
|
2
2
|
import { Modal } from './modal';
|
|
3
3
|
/**
|
|
4
4
|
* A simple example modal that displays a message to the user
|
|
5
|
+
* TODO: Replace with a dedicated command
|
|
6
|
+
* @ignore
|
|
5
7
|
*/
|
|
6
8
|
export declare class AlertModal extends Modal {
|
|
7
|
-
protected readonly client: EditorClient;
|
|
8
9
|
constructor(client: EditorClient, title: string, message: string);
|
|
9
|
-
protected messageFromFrame(message: any): void;
|
|
10
|
-
protected frameLoaded(): void;
|
|
11
10
|
}
|
package/sdk/ui/alertmodal.js
CHANGED
|
@@ -4,6 +4,8 @@ exports.AlertModal = void 0;
|
|
|
4
4
|
const modal_1 = require("./modal");
|
|
5
5
|
/**
|
|
6
6
|
* A simple example modal that displays a message to the user
|
|
7
|
+
* TODO: Replace with a dedicated command
|
|
8
|
+
* @ignore
|
|
7
9
|
*/
|
|
8
10
|
class AlertModal extends modal_1.Modal {
|
|
9
11
|
constructor(client, title, message) {
|
|
@@ -32,9 +34,6 @@ p {
|
|
|
32
34
|
</html>
|
|
33
35
|
`,
|
|
34
36
|
});
|
|
35
|
-
this.client = client;
|
|
36
37
|
}
|
|
37
|
-
messageFromFrame(message) { }
|
|
38
|
-
frameLoaded() { }
|
|
39
38
|
}
|
|
40
39
|
exports.AlertModal = AlertModal;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { JsonSerializable } from '../core/jsonserializable';
|
|
2
|
+
import { EditorClient } from '../editorclient';
|
|
3
|
+
/** @ignore */
|
|
4
|
+
export declare enum IncomingUIMessageType {
|
|
5
|
+
Closed = 1,
|
|
6
|
+
PostMessageFromFrame = 2,
|
|
7
|
+
FrameLoaded = 3
|
|
8
|
+
}
|
|
9
|
+
/** @ignore */
|
|
10
|
+
export interface IncomingUIMessage {
|
|
11
|
+
'id': string;
|
|
12
|
+
't': IncomingUIMessageType;
|
|
13
|
+
'data'?: any;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Base class for defining and interacting with custom UI elements whose contents are displayed
|
|
17
|
+
* in an iframe.
|
|
18
|
+
*/
|
|
19
|
+
export declare abstract class IframeUI {
|
|
20
|
+
protected readonly client: EditorClient;
|
|
21
|
+
private static nextId;
|
|
22
|
+
private id;
|
|
23
|
+
private static uiMessageActionNamePrefix;
|
|
24
|
+
protected messageActionName: string;
|
|
25
|
+
protected loaded: boolean;
|
|
26
|
+
constructor(client: EditorClient);
|
|
27
|
+
/** @ignore */
|
|
28
|
+
static isUIMessageActionName(name: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Subclasses must call hookMessages some time before the UI is displayed. A Modal
|
|
31
|
+
* will call this when the open() method is called, where a Panel will need to do
|
|
32
|
+
* this in the constructor to watch for the user opening the panel.
|
|
33
|
+
*/
|
|
34
|
+
protected hookMessages(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Subclasses must call unhookMessages to allow them to be garbage collected.
|
|
37
|
+
*/
|
|
38
|
+
protected unhookMessages(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Send a message to this UI component's iframe via window.postMessage.
|
|
41
|
+
* @param data Data to send to the iframe
|
|
42
|
+
*/
|
|
43
|
+
sendMessage(data: JsonSerializable): void;
|
|
44
|
+
/**
|
|
45
|
+
* Receives messages sent from the iframe via parent.postMessage(<data>, '*')
|
|
46
|
+
* @param message data sent from the iframe
|
|
47
|
+
*/
|
|
48
|
+
protected messageFromFrame(message: any): void;
|
|
49
|
+
/**
|
|
50
|
+
* Called when the iframe has been constructed, its srcdoc set, and the window loaded event has fired
|
|
51
|
+
*/
|
|
52
|
+
protected frameLoaded(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Called when the iframe has been removed from the DOM
|
|
55
|
+
*/
|
|
56
|
+
protected frameClosed(): void;
|
|
57
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IframeUI = exports.IncomingUIMessageType = void 0;
|
|
4
|
+
/** @ignore */
|
|
5
|
+
var IncomingUIMessageType;
|
|
6
|
+
(function (IncomingUIMessageType) {
|
|
7
|
+
IncomingUIMessageType[IncomingUIMessageType["Closed"] = 1] = "Closed";
|
|
8
|
+
IncomingUIMessageType[IncomingUIMessageType["PostMessageFromFrame"] = 2] = "PostMessageFromFrame";
|
|
9
|
+
IncomingUIMessageType[IncomingUIMessageType["FrameLoaded"] = 3] = "FrameLoaded";
|
|
10
|
+
})(IncomingUIMessageType = exports.IncomingUIMessageType || (exports.IncomingUIMessageType = {}));
|
|
11
|
+
/**
|
|
12
|
+
* Base class for defining and interacting with custom UI elements whose contents are displayed
|
|
13
|
+
* in an iframe.
|
|
14
|
+
*/
|
|
15
|
+
class IframeUI {
|
|
16
|
+
constructor(client) {
|
|
17
|
+
this.client = client;
|
|
18
|
+
this.id = ++IframeUI.nextId;
|
|
19
|
+
this.messageActionName = IframeUI.uiMessageActionNamePrefix + this.id;
|
|
20
|
+
this.loaded = false;
|
|
21
|
+
}
|
|
22
|
+
/** @ignore */
|
|
23
|
+
static isUIMessageActionName(name) {
|
|
24
|
+
return name.startsWith(IframeUI.uiMessageActionNamePrefix);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Subclasses must call hookMessages some time before the UI is displayed. A Modal
|
|
28
|
+
* will call this when the open() method is called, where a Panel will need to do
|
|
29
|
+
* this in the constructor to watch for the user opening the panel.
|
|
30
|
+
*/
|
|
31
|
+
hookMessages() {
|
|
32
|
+
this.client.registerAction(this.messageActionName, (message) => {
|
|
33
|
+
switch (message['t']) {
|
|
34
|
+
case IncomingUIMessageType.Closed:
|
|
35
|
+
this.loaded = false;
|
|
36
|
+
this.frameClosed();
|
|
37
|
+
break;
|
|
38
|
+
case IncomingUIMessageType.PostMessageFromFrame:
|
|
39
|
+
this.messageFromFrame(message['data']);
|
|
40
|
+
break;
|
|
41
|
+
case IncomingUIMessageType.FrameLoaded:
|
|
42
|
+
this.loaded = true;
|
|
43
|
+
this.frameLoaded();
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Subclasses must call unhookMessages to allow them to be garbage collected.
|
|
50
|
+
*/
|
|
51
|
+
unhookMessages() {
|
|
52
|
+
this.client.deleteAction(this.messageActionName);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Send a message to this UI component's iframe via window.postMessage.
|
|
56
|
+
* @param data Data to send to the iframe
|
|
57
|
+
*/
|
|
58
|
+
sendMessage(data) {
|
|
59
|
+
if (this.loaded) {
|
|
60
|
+
this.client.sendCommand("suim" /* SendUIMessage */, {
|
|
61
|
+
'n': this.messageActionName,
|
|
62
|
+
'd': data,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Receives messages sent from the iframe via parent.postMessage(<data>, '*')
|
|
68
|
+
* @param message data sent from the iframe
|
|
69
|
+
*/
|
|
70
|
+
messageFromFrame(message) { }
|
|
71
|
+
/**
|
|
72
|
+
* Called when the iframe has been constructed, its srcdoc set, and the window loaded event has fired
|
|
73
|
+
*/
|
|
74
|
+
frameLoaded() { }
|
|
75
|
+
/**
|
|
76
|
+
* Called when the iframe has been removed from the DOM
|
|
77
|
+
*/
|
|
78
|
+
frameClosed() { }
|
|
79
|
+
}
|
|
80
|
+
exports.IframeUI = IframeUI;
|
|
81
|
+
IframeUI.nextId = 0;
|
|
82
|
+
IframeUI.uiMessageActionNamePrefix = '__ui_message__';
|
package/sdk/ui/modal.d.ts
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import { JsonSerializable } from '../core/jsonserializable';
|
|
2
1
|
import { EditorClient } from '../editorclient';
|
|
2
|
+
import { IframeUI } from './iframeui';
|
|
3
|
+
/**
|
|
4
|
+
* Configuration required to display a [Modal](#classes_ui_modal-Modal).
|
|
5
|
+
*/
|
|
3
6
|
export interface ModalConfig {
|
|
7
|
+
/** Title to display in the header bar of the modal. */
|
|
4
8
|
title: string;
|
|
9
|
+
/** Requested width of the modal, in pixels. Depending on window size, this may not be honored exactly. */
|
|
5
10
|
width: number;
|
|
11
|
+
/** Requested height of the modal, in pixels. Depending on window size, this may not be honored exactly. */
|
|
6
12
|
height: number;
|
|
7
13
|
/** Content to display in the modal's iframe. This is set as the srcdoc on a sandboxed iframe. */
|
|
8
14
|
content: string;
|
|
9
15
|
}
|
|
10
|
-
export declare enum ModalIncomingMessageType {
|
|
11
|
-
ModalClosed = 1,
|
|
12
|
-
PostMessageFromFrame = 2,
|
|
13
|
-
FrameLoaded = 3
|
|
14
|
-
}
|
|
15
|
-
export interface ModalIncomingMessage {
|
|
16
|
-
'id': string;
|
|
17
|
-
't': ModalIncomingMessageType;
|
|
18
|
-
'data'?: any;
|
|
19
|
-
}
|
|
20
16
|
/**
|
|
21
17
|
* Extend this class to show a custom modal to the user, whose contents are displayed in a sandboxed
|
|
22
18
|
* iframe controlled by your extension.
|
|
@@ -27,32 +23,14 @@ export interface ModalIncomingMessage {
|
|
|
27
23
|
* To pass messages back from the modal to this class, call parent.postMessage from within the iframe.
|
|
28
24
|
* The data sent will be passed along to the messageFromFrame implementation on your Modal class.
|
|
29
25
|
*/
|
|
30
|
-
export declare abstract class Modal {
|
|
31
|
-
protected readonly client: EditorClient;
|
|
26
|
+
export declare abstract class Modal extends IframeUI {
|
|
32
27
|
private readonly config;
|
|
33
|
-
private static nextId;
|
|
34
|
-
private id;
|
|
35
|
-
private static modalMessageActionNamePrefix;
|
|
36
|
-
private messageActionName;
|
|
37
28
|
private visible;
|
|
38
29
|
constructor(client: EditorClient, config: ModalConfig);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
private unhookMessages;
|
|
42
|
-
/**
|
|
43
|
-
* Send a message to this modal's iframe via window.postMessage.
|
|
44
|
-
* @param data Data to send to the iframe
|
|
45
|
-
*/
|
|
46
|
-
sendMessage(data: JsonSerializable): void;
|
|
47
|
-
/**
|
|
48
|
-
* Receives messages sent from the iframe via parent.postMessage(<data>, '*')
|
|
49
|
-
* @param message data sent from the iframe
|
|
50
|
-
*/
|
|
51
|
-
protected abstract messageFromFrame(message: any): void;
|
|
30
|
+
protected frameClosed(): void;
|
|
31
|
+
show(): void;
|
|
52
32
|
/**
|
|
53
|
-
*
|
|
33
|
+
* If this modal is currently visible, close it, destroying the iframe.
|
|
54
34
|
*/
|
|
55
|
-
protected abstract frameLoaded(): void;
|
|
56
|
-
show(): void;
|
|
57
35
|
hide(): void;
|
|
58
36
|
}
|
package/sdk/ui/modal.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Modal =
|
|
4
|
-
|
|
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 = {}));
|
|
3
|
+
exports.Modal = void 0;
|
|
4
|
+
const iframeui_1 = require("./iframeui");
|
|
10
5
|
/**
|
|
11
6
|
* Extend this class to show a custom modal to the user, whose contents are displayed in a sandboxed
|
|
12
7
|
* iframe controlled by your extension.
|
|
@@ -17,47 +12,14 @@ var ModalIncomingMessageType;
|
|
|
17
12
|
* To pass messages back from the modal to this class, call parent.postMessage from within the iframe.
|
|
18
13
|
* The data sent will be passed along to the messageFromFrame implementation on your Modal class.
|
|
19
14
|
*/
|
|
20
|
-
class Modal {
|
|
15
|
+
class Modal extends iframeui_1.IframeUI {
|
|
21
16
|
constructor(client, config) {
|
|
22
|
-
|
|
17
|
+
super(client);
|
|
23
18
|
this.config = config;
|
|
24
|
-
this.id = ++Modal.nextId;
|
|
25
|
-
this.messageActionName = Modal.modalMessageActionNamePrefix + this.id;
|
|
26
19
|
this.visible = false;
|
|
27
20
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
hookMessages() {
|
|
32
|
-
this.client.registerAction(this.messageActionName, (message) => {
|
|
33
|
-
switch (message['t']) {
|
|
34
|
-
case ModalIncomingMessageType.ModalClosed:
|
|
35
|
-
this.unhookMessages();
|
|
36
|
-
this.visible = false;
|
|
37
|
-
break;
|
|
38
|
-
case ModalIncomingMessageType.PostMessageFromFrame:
|
|
39
|
-
this.messageFromFrame(message['data']);
|
|
40
|
-
break;
|
|
41
|
-
case ModalIncomingMessageType.FrameLoaded:
|
|
42
|
-
this.frameLoaded();
|
|
43
|
-
break;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
unhookMessages() {
|
|
48
|
-
this.client.deleteAction(this.messageActionName);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Send a message to this modal's iframe via window.postMessage.
|
|
52
|
-
* @param data Data to send to the iframe
|
|
53
|
-
*/
|
|
54
|
-
sendMessage(data) {
|
|
55
|
-
if (this.visible) {
|
|
56
|
-
this.client.sendCommand("suim" /* SendUIMessage */, {
|
|
57
|
-
'n': this.messageActionName,
|
|
58
|
-
'd': data,
|
|
59
|
-
});
|
|
60
|
-
}
|
|
21
|
+
frameClosed() {
|
|
22
|
+
this.unhookMessages();
|
|
61
23
|
}
|
|
62
24
|
show() {
|
|
63
25
|
if (!this.visible) {
|
|
@@ -72,6 +34,9 @@ class Modal {
|
|
|
72
34
|
this.visible = true;
|
|
73
35
|
}
|
|
74
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* If this modal is currently visible, close it, destroying the iframe.
|
|
39
|
+
*/
|
|
75
40
|
hide() {
|
|
76
41
|
if (this.visible) {
|
|
77
42
|
this.client.sendCommand("hm" /* HideModal */, { 'n': this.messageActionName });
|
|
@@ -80,5 +45,3 @@ class Modal {
|
|
|
80
45
|
}
|
|
81
46
|
}
|
|
82
47
|
exports.Modal = Modal;
|
|
83
|
-
Modal.nextId = 0;
|
|
84
|
-
Modal.modalMessageActionNamePrefix = '__modal_message__';
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { EditorClient } from '../editorclient';
|
|
2
|
+
import { IframeUI } from './iframeui';
|
|
3
|
+
/**
|
|
4
|
+
* Semantic locations to place a new menu item.
|
|
5
|
+
*/
|
|
6
|
+
export declare enum PanelLocation {
|
|
7
|
+
/** In Lucidchart, create a sibling to the Contextual Panel */
|
|
8
|
+
RightDock = 1
|
|
9
|
+
}
|
|
10
|
+
export interface PanelConfig {
|
|
11
|
+
/** Title to display at the top of the panel */
|
|
12
|
+
title: string;
|
|
13
|
+
/** Content to display in the panel's iframe. This is set as the srcdoc on a sandboxed iframe. */
|
|
14
|
+
content: string;
|
|
15
|
+
/** Location to display the panel */
|
|
16
|
+
location: PanelLocation;
|
|
17
|
+
/** If specified, what action's return value should determine if the button to toggle this panel is visible? */
|
|
18
|
+
visibleAction?: string;
|
|
19
|
+
/** The URL for an icon to represent the panel, preferably base64-encoded. Will be displayed at 24x24 CSS pixels in size. */
|
|
20
|
+
iconUrl: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Extend this class to show a custom panel to the user, whose contents are displayed in a sandboxed
|
|
24
|
+
* iframe controlled by your extension.
|
|
25
|
+
*
|
|
26
|
+
* To pass a message to a script running in the panel, call sendMessage. The data you pass in will be
|
|
27
|
+
* sent to the iframe with window.postMessage.
|
|
28
|
+
*
|
|
29
|
+
* To pass messages back from the panel to this class, call parent.postMessage from within the iframe.
|
|
30
|
+
* The data sent will be passed along to the messageFromFrame implementation on your Panel class.
|
|
31
|
+
*/
|
|
32
|
+
export declare abstract class Panel extends IframeUI {
|
|
33
|
+
protected readonly config: PanelConfig;
|
|
34
|
+
constructor(client: EditorClient, config: PanelConfig);
|
|
35
|
+
/**
|
|
36
|
+
* Show this panel in its specified location, if it is not already visible.
|
|
37
|
+
*/
|
|
38
|
+
show(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Hide this panel if it is currently visible.
|
|
41
|
+
*/
|
|
42
|
+
hide(): void;
|
|
43
|
+
}
|
package/sdk/ui/panel.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Panel = exports.PanelLocation = void 0;
|
|
4
|
+
const iframeui_1 = require("./iframeui");
|
|
5
|
+
/**
|
|
6
|
+
* Semantic locations to place a new menu item.
|
|
7
|
+
*/
|
|
8
|
+
var PanelLocation;
|
|
9
|
+
(function (PanelLocation) {
|
|
10
|
+
/** In Lucidchart, create a sibling to the Contextual Panel */
|
|
11
|
+
PanelLocation[PanelLocation["RightDock"] = 1] = "RightDock";
|
|
12
|
+
})(PanelLocation = exports.PanelLocation || (exports.PanelLocation = {}));
|
|
13
|
+
/**
|
|
14
|
+
* Extend this class to show a custom panel to the user, whose contents are displayed in a sandboxed
|
|
15
|
+
* iframe controlled by your extension.
|
|
16
|
+
*
|
|
17
|
+
* To pass a message to a script running in the panel, call sendMessage. The data you pass in will be
|
|
18
|
+
* sent to the iframe with window.postMessage.
|
|
19
|
+
*
|
|
20
|
+
* To pass messages back from the panel to this class, call parent.postMessage from within the iframe.
|
|
21
|
+
* The data sent will be passed along to the messageFromFrame implementation on your Panel class.
|
|
22
|
+
*/
|
|
23
|
+
class Panel extends iframeui_1.IframeUI {
|
|
24
|
+
constructor(client, config) {
|
|
25
|
+
super(client);
|
|
26
|
+
this.config = config;
|
|
27
|
+
this.hookMessages();
|
|
28
|
+
this.client.sendCommand("rp" /* RegisterPanel */, {
|
|
29
|
+
'n': this.messageActionName,
|
|
30
|
+
't': this.config.title,
|
|
31
|
+
'l': this.config.location,
|
|
32
|
+
'c': this.config.content,
|
|
33
|
+
'v': this.config.visibleAction,
|
|
34
|
+
'i': this.config.iconUrl,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Show this panel in its specified location, if it is not already visible.
|
|
39
|
+
*/
|
|
40
|
+
show() {
|
|
41
|
+
this.client.sendCommand("spn" /* ShowPanel */, { 'n': this.messageActionName });
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Hide this panel if it is currently visible.
|
|
45
|
+
*/
|
|
46
|
+
hide() {
|
|
47
|
+
this.client.sendCommand("hp" /* HidePanel */, { 'n': this.messageActionName });
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.Panel = Panel;
|
package/sdk/ui/viewport.d.ts
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { ItemProxy } from '../document/itemproxy';
|
|
2
2
|
import { PageProxy } from '../document/pageproxy';
|
|
3
3
|
import { EditorClient } from '../editorclient';
|
|
4
|
+
/**
|
|
5
|
+
* A text editing hook provided to [Viewport.hookTextEdit](/extension-sdk/#classes_ui_viewport-Viewport_hooktextedit)
|
|
6
|
+
* may return a TextEditCompletionCallback to specify what behavior should happen when the user finishes editing text.
|
|
7
|
+
*
|
|
8
|
+
* If this callback returns false, the edit is reverted.
|
|
9
|
+
*
|
|
10
|
+
* If this callback returns a string, the typed value is replaced with that string.
|
|
11
|
+
*/
|
|
12
|
+
export declare type TextEditCompletionCallback = (newValue: string) => boolean | string | Promise<boolean | string>;
|
|
4
13
|
export declare class Viewport {
|
|
5
14
|
private readonly client;
|
|
15
|
+
private static nextHookId;
|
|
6
16
|
constructor(client: EditorClient);
|
|
17
|
+
private static nextHookName;
|
|
7
18
|
/**
|
|
8
19
|
* @param deep If true, and groups are selected, include the contents of those groups in the array
|
|
9
20
|
* @returns An array of currently-selected items on the currently-visible page
|
|
@@ -24,4 +35,38 @@ export declare class Viewport {
|
|
|
24
35
|
* @param items The items the camera should zoom to
|
|
25
36
|
*/
|
|
26
37
|
focusCameraOnItems(items: ItemProxy[]): void;
|
|
38
|
+
/**
|
|
39
|
+
* If `callback` returns false, text editing is prevented.
|
|
40
|
+
* If `callback` returns true, text editing continues as normal.
|
|
41
|
+
*
|
|
42
|
+
* If `callback` returns a [TextEditCompletionCallback](/extension-sdk/#modules_ui_viewport_texteditcompletioncallback), then text editing
|
|
43
|
+
* is allowed, but that completion callback is called
|
|
44
|
+
* when the user finishes editing that text. That completion callback may return true or false to allow or deny the edit, or
|
|
45
|
+
* also may return a replacement string to use instead of the text the user actually typed. If replacement text is provided,
|
|
46
|
+
* it will be styled as close to the original as possible, but styles that apply to only parts of the original text will be
|
|
47
|
+
* discarded.
|
|
48
|
+
*
|
|
49
|
+
* @param callback Called just before the user starts editing text.
|
|
50
|
+
*
|
|
51
|
+
* @returns A handle representing this hook, which can be passed to unhookTextEdit to remove this hook.
|
|
52
|
+
*/
|
|
53
|
+
hookTextEdit(callback: (item: ItemProxy, textAreaKey: string) => boolean | TextEditCompletionCallback | Promise<boolean | TextEditCompletionCallback>): string;
|
|
54
|
+
/**
|
|
55
|
+
* Remove a hook set by hookTextEdit.
|
|
56
|
+
*
|
|
57
|
+
* @param handle The return value of hookTextEdit.
|
|
58
|
+
*/
|
|
59
|
+
unhookTextEdit(handle: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* @param callback Called when the user changes their selection of items
|
|
62
|
+
*
|
|
63
|
+
* @returns A handle representing this hook, which can be passed to unhookSelection to remove this hook.
|
|
64
|
+
*/
|
|
65
|
+
hookSelection(callback: (items: ItemProxy[]) => void): string;
|
|
66
|
+
/**
|
|
67
|
+
* Remove a hook set by hookSelection.
|
|
68
|
+
*
|
|
69
|
+
* @param handle The return value of hookSelection.
|
|
70
|
+
*/
|
|
71
|
+
unhookSelection(handle: string): void;
|
|
27
72
|
}
|