lucid-extension-sdk 0.0.205 → 0.0.207

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.
@@ -0,0 +1,6 @@
1
+ export interface DeferredPromise<T> extends Promise<T> {
2
+ resolve: (p1: T) => any;
3
+ reject: (p1?: any) => any;
4
+ promise: Promise<T>;
5
+ }
6
+ export declare function defer<T = void>(): DeferredPromise<T>;
package/core/defer.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defer = void 0;
4
+ function checkPromiseExists() {
5
+ if (typeof Promise !== 'function') {
6
+ throw new Error('No promise library available');
7
+ }
8
+ }
9
+ function defer() {
10
+ checkPromiseExists();
11
+ let resolve = undefined;
12
+ let reject = undefined;
13
+ const promise = new Promise((resolveLocal, rejectLocal) => {
14
+ resolve = resolveLocal;
15
+ reject = rejectLocal;
16
+ });
17
+ if (!resolve || !reject) {
18
+ throw new Error('Promise constructor does not provide proper arguments to callback');
19
+ }
20
+ return {
21
+ resolve: resolve,
22
+ reject: reject,
23
+ promise: promise,
24
+ then: promise.then.bind(promise),
25
+ catch: promise.catch.bind(promise),
26
+ finally: promise.finally.bind(promise),
27
+ [Symbol.toStringTag]: promise[Symbol.toStringTag],
28
+ };
29
+ }
30
+ exports.defer = defer;
@@ -1,4 +1,5 @@
1
1
  import { SimpleImageFill } from '../core/properties/fillcolor';
2
+ import { StrokeStyle } from '../core/properties/strokestyle';
2
3
  import { Box } from '../math';
3
4
  /**
4
5
  * The information required to create a new image block on the current document
@@ -12,4 +13,28 @@ export interface ImageDefinition {
12
13
  * Settings for using an image as the fill style of a block.
13
14
  */
14
15
  fillStyle: SimpleImageFill;
16
+ /**
17
+ * The opacity (0 - 1) for this image (default is 1).
18
+ */
19
+ opacity?: number;
20
+ /**
21
+ * the border color for this image (default is black, #000000).
22
+ */
23
+ lineColor?: string;
24
+ /**
25
+ * The border width in pixels for this image (default is 1).
26
+ */
27
+ lineWidth?: number;
28
+ /**
29
+ * The stroke style for the border of this image (default is Solid).
30
+ */
31
+ strokeStyle?: StrokeStyle;
32
+ /**
33
+ * The rounding for this image (default is 0).
34
+ */
35
+ rounding?: number;
36
+ /**
37
+ * The rotation for this image (deafult is 0).
38
+ */
39
+ rotation?: number;
15
40
  }
@@ -69,15 +69,15 @@ export declare class PageProxy extends ElementProxy {
69
69
  */
70
70
  addBlock(def: BlockDefinition): BlockProxy;
71
71
  /**
72
- * Add a new line to this page
72
+ * Add a new line to this page.
73
73
  * @param def The definition of the new line to add
74
74
  * @returns The added line
75
75
  */
76
76
  addLine(def: LineDefinition): LineProxy;
77
77
  /**
78
- * Add a new image to this page
78
+ * Add a new image to this page.
79
79
  * @param def The definition of the new image to add
80
- * @returns The added image block
80
+ * @returns The added image
81
81
  */
82
82
  addImage(def: ImageDefinition): Promise<BlockProxy>;
83
83
  /**
@@ -100,7 +100,7 @@ class PageProxy extends elementproxy_1.ElementProxy {
100
100
  return block;
101
101
  }
102
102
  /**
103
- * Add a new line to this page
103
+ * Add a new line to this page.
104
104
  * @param def The definition of the new line to add
105
105
  * @returns The added line
106
106
  */
@@ -114,13 +114,25 @@ class PageProxy extends elementproxy_1.ElementProxy {
114
114
  return line;
115
115
  }
116
116
  /**
117
- * Add a new image to this page
117
+ * Add a new image to this page.
118
118
  * @param def The definition of the new image to add
119
- * @returns The added image block
119
+ * @returns The added image
120
120
  */
121
121
  async addImage(def) {
122
122
  await this.client.loadBlockClasses(['UserImage2Block']);
123
- return this.addBlock(Object.assign({ className: 'UserImage2Block' }, def));
123
+ return this.addBlock({
124
+ className: 'UserImage2Block',
125
+ boundingBox: def.boundingBox,
126
+ fillStyle: def.fillStyle,
127
+ properties: {
128
+ opactiy: def.opacity,
129
+ lineColor: def.lineColor,
130
+ lineWidth: def.lineWidth,
131
+ strokeStyle: def.strokeStyle,
132
+ rounding: def.rounding,
133
+ rotation: def.rotation,
134
+ },
135
+ });
124
136
  }
125
137
  /**
126
138
  * Updates the page of this page
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-extension-sdk",
3
- "version": "0.0.205",
3
+ "version": "0.0.207",
4
4
  "description": "Utility classes for writing Lucid Software editor extensions",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
package/ui/iframeui.d.ts CHANGED
@@ -25,6 +25,7 @@ export declare abstract class IframeUI {
25
25
  protected messageActionName: string;
26
26
  /** True after the iframe has fired an onload event (not all scripts are necessarily finished executing) */
27
27
  protected loaded: boolean;
28
+ private frameLoadedPromise;
28
29
  /**
29
30
  * The location of this frame within the top-level browser window. This is always updated immediately before
30
31
  * `messageFromFrame` is called.
@@ -52,7 +53,7 @@ export declare abstract class IframeUI {
52
53
  * Send a message to this UI component's iframe via window.postMessage.
53
54
  * @param data Data to send to the iframe
54
55
  */
55
- sendMessage(data: JsonSerializable): void;
56
+ sendMessage(data: JsonSerializable): Promise<void>;
56
57
  /**
57
58
  * Receives messages sent from the iframe via parent.postMessage(<data>, '*')
58
59
  * @param message data sent from the iframe
package/ui/iframeui.js CHANGED
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IframeUI = exports.IncomingUIMessageType = void 0;
4
+ const defer_1 = require("../core/defer");
4
5
  /** @ignore */
5
6
  var IncomingUIMessageType;
6
7
  (function (IncomingUIMessageType) {
@@ -20,6 +21,7 @@ class IframeUI {
20
21
  this.messageActionName = IframeUI.uiMessageActionNamePrefix + this.id;
21
22
  /** True after the iframe has fired an onload event (not all scripts are necessarily finished executing) */
22
23
  this.loaded = false;
24
+ this.frameLoadedPromise = (0, defer_1.defer)();
23
25
  /**
24
26
  * The location of this frame within the top-level browser window. This is always updated immediately before
25
27
  * `messageFromFrame` is called.
@@ -50,6 +52,7 @@ class IframeUI {
50
52
  break;
51
53
  case IncomingUIMessageType.FrameLoaded:
52
54
  this.loaded = true;
55
+ this.frameLoadedPromise.resolve();
53
56
  this.frameLoaded();
54
57
  break;
55
58
  }
@@ -65,13 +68,12 @@ class IframeUI {
65
68
  * Send a message to this UI component's iframe via window.postMessage.
66
69
  * @param data Data to send to the iframe
67
70
  */
68
- sendMessage(data) {
69
- if (this.loaded) {
70
- this.client.sendCommand("suim" /* CommandName.SendUIMessage */, {
71
- 'n': this.messageActionName,
72
- 'd': data,
73
- });
74
- }
71
+ async sendMessage(data) {
72
+ await this.frameLoadedPromise;
73
+ this.client.sendCommand("suim" /* CommandName.SendUIMessage */, {
74
+ 'n': this.messageActionName,
75
+ 'd': data,
76
+ });
75
77
  }
76
78
  /**
77
79
  * Receives messages sent from the iframe via parent.postMessage(<data>, '*')