lucid-extension-sdk 0.0.4 → 0.0.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-extension-sdk",
3
- "version": "0.0.4",
3
+ "version": "0.0.8",
4
4
  "description": "Utility classes for writing Lucid Software editor extensions",
5
5
  "main": "sdk/index.js",
6
6
  "types": "sdk/index.d.ts",
@@ -11,6 +11,7 @@ export declare const enum CommandName {
11
11
  AddMenuItem = "ami",
12
12
  AddShapeData = "asd",
13
13
  AnimateViewport = "av",
14
+ Bootstrap = "b",
14
15
  CreateBlock = "cb",
15
16
  CreateCollection = "cc",
16
17
  CreateDataSource = "cds",
@@ -52,13 +53,15 @@ export declare const enum CommandName {
52
53
  OffsetItems = "oi",
53
54
  PatchDataItems = "pdi",
54
55
  ReloadExtension = "r",
56
+ SendOAuthRequest = "oauth",
55
57
  SendUIMessage = "suim",
56
58
  SendXHR = "xhr",
57
59
  SetCurrentPage = "scp",
58
60
  SetProperty = "sp",
59
61
  SetReferenceKey = "srk",
60
62
  SetShapeData = "ssd",
61
- ShowModal = "sm"
63
+ ShowModal = "sm",
64
+ SleepForTestCase = "sleep"
62
65
  }
63
66
  export declare type CommandArgs = {
64
67
  [CommandName.AnimateViewport]: {
@@ -73,6 +76,10 @@ export declare type CommandArgs = {
73
76
  query: AddShapeDataQuery;
74
77
  result: AddShapeDataResult;
75
78
  };
79
+ [CommandName.Bootstrap]: {
80
+ query: BootstrapQuery;
81
+ result: BootstrapResult;
82
+ };
76
83
  [CommandName.CreateBlock]: {
77
84
  query: CreateBlockQuery;
78
85
  result: CreateBlockResult;
@@ -237,6 +244,10 @@ export declare type CommandArgs = {
237
244
  query: ReloadExtensionQuery;
238
245
  result: ReloadExtensionResult;
239
246
  };
247
+ [CommandName.SendOAuthRequest]: {
248
+ query: SendOAuthRequestQuery;
249
+ result: SendOAuthRequestResponse;
250
+ };
240
251
  [CommandName.SendUIMessage]: {
241
252
  query: SendUIMessageQuery;
242
253
  result: SendUIMessageResult;
@@ -265,6 +276,10 @@ export declare type CommandArgs = {
265
276
  query: ShowModalQuery;
266
277
  result: ShowModalResult;
267
278
  };
279
+ [CommandName.SleepForTestCase]: {
280
+ query: SleepForTestCaseQuery;
281
+ result: SleepForTestCaseResult;
282
+ };
268
283
  };
269
284
  export declare type UnionToIntersection<T> = (T extends any ? (x: T) => unknown : never) extends (x: infer R) => unknown ? R : never;
270
285
  export declare type AddMenuItemQuery = {
@@ -283,6 +298,14 @@ export declare type AddShapeDataQuery = {
283
298
  'v'?: SerializedFieldType;
284
299
  };
285
300
  export declare type AddShapeDataResult = undefined;
301
+ export declare type BootstrapQuery = {
302
+ /**
303
+ * Named action that accepts the bootstrap data, and which may return a Promise or void. After awaiting\
304
+ * the result of the callback, the bootstrap data is cleared.
305
+ */
306
+ 'c': string;
307
+ };
308
+ export declare type BootstrapResult = Promise<void>;
286
309
  export declare type CreateBlockQuery = {
287
310
  'p'?: string;
288
311
  'c': string;
@@ -451,6 +474,10 @@ export declare type PatchDataItemsQuery = {
451
474
  export declare type PatchDataItemsResult = undefined;
452
475
  export declare type ReloadExtensionQuery = void;
453
476
  export declare type ReloadExtensionResult = undefined;
477
+ export declare type SendOAuthRequestQuery = SendXHRQuery & {
478
+ 'p': string;
479
+ };
480
+ export declare type SendOAuthRequestResponse = SendXHRResponse;
454
481
  export declare type SendUIMessageQuery = {
455
482
  'n': string;
456
483
  'd'?: JsonSerializable;
@@ -511,3 +538,5 @@ export declare type ShowModalQuery = {
511
538
  'c': string;
512
539
  };
513
540
  export declare type ShowModalResult = undefined;
541
+ export declare type SleepForTestCaseQuery = number;
542
+ export declare type SleepForTestCaseResult = Promise<void>;
@@ -15,7 +15,7 @@ export interface BlockDefinition {
15
15
  /**
16
16
  * Additional properties to set on the block immediately after creation
17
17
  */
18
- properties: JsonObject;
18
+ properties?: JsonObject;
19
19
  /**
20
20
  * If specified, the stencil to use for a custom shape. This is not typically set directly; use
21
21
  * PageProxy.getCustomShapeDefinition().
@@ -18,4 +18,13 @@ export declare class DocumentProxy extends ElementProxy {
18
18
  * @returns the created page
19
19
  */
20
20
  addPage(def: PageDefinition): PageProxy;
21
+ /**
22
+ * Updates the title of this document
23
+ * @param title The new title for this document
24
+ */
25
+ setTitle(title: string): void;
26
+ /**
27
+ * @returns the title of this document
28
+ */
29
+ getTitle(): string;
21
30
  }
@@ -26,5 +26,18 @@ class DocumentProxy extends elementproxy_1.ElementProxy {
26
26
  page.setTitle(def.title);
27
27
  return page;
28
28
  }
29
+ /**
30
+ * Updates the title of this document
31
+ * @param title The new title for this document
32
+ */
33
+ setTitle(title) {
34
+ this.properties.set('Title', title);
35
+ }
36
+ /**
37
+ * @returns the title of this document
38
+ */
39
+ getTitle() {
40
+ return this.properties.get('Title');
41
+ }
29
42
  }
30
43
  exports.DocumentProxy = DocumentProxy;
@@ -59,8 +59,10 @@ class PageProxy extends elementproxy_1.ElementProxy {
59
59
  });
60
60
  const block = this.client.getBlockProxy(id);
61
61
  block.setBoundingBox(def.boundingBox);
62
- for (const key in def.properties) {
63
- block.properties.set(key, def.properties[key]);
62
+ if (def.properties) {
63
+ for (const key in def.properties) {
64
+ block.properties.set(key, def.properties[key]);
65
+ }
64
66
  }
65
67
  return block;
66
68
  }
@@ -36,6 +36,7 @@ export interface XHRResponse {
36
36
  export declare class EditorClient {
37
37
  private nextId;
38
38
  private readonly callbacks;
39
+ private getUniqueActionName;
39
40
  /**
40
41
  * Unload this extension immediately, removing any custom menu items etc., until the user refreshes the browser tab.
41
42
  */
@@ -59,6 +60,7 @@ export declare class EditorClient {
59
60
  * code is not 2xx, the promise will reject.
60
61
  */
61
62
  xhr(request: XHRRequest): Promise<XHRResponse>;
63
+ oauthXhr(providerName: string, request: XHRRequest): Promise<XHRResponse>;
62
64
  /**
63
65
  * Register a named action. These actions can be triggered from custom UI, for example as the action of a
64
66
  * custom menu item.
@@ -142,6 +144,17 @@ export declare class EditorClient {
142
144
  * @returns
143
145
  */
144
146
  getCustomShapeDefinition(library: string, shape: string): Promise<BlockDefinition | undefined>;
147
+ /**
148
+ * @param callback A callback that processes the bootstrap data, if any, stored on the document and
149
+ * associated with this editor extension. If this callback is async (returns a promise), then the
150
+ * bootstrap data is not cleared off of the document until that promise resolves.
151
+ *
152
+ * @return a promise that resolves immediately if there is no available bootstrap data, or else after
153
+ * the callback successfully completes. This promise will reject/throw if the callback throws or
154
+ * returns a promise that rejects, or if there is another editor session processing the same bootstrap
155
+ * data at the same time.
156
+ */
157
+ processAndClearBootstrapData(callback: (data: JsonSerializable) => void | Promise<void>): Promise<void>;
145
158
  /**
146
159
  * @param id ID of the line to create a proxy for
147
160
  * @returns the given line
@@ -15,6 +15,12 @@ class EditorClient {
15
15
  this.callbacks = new Map();
16
16
  this.listenToEditor();
17
17
  }
18
+ getUniqueActionName() {
19
+ while (this.actionExists('a' + this.nextId)) {
20
+ this.nextId++;
21
+ }
22
+ return 'a' + this.nextId;
23
+ }
18
24
  /**
19
25
  * Unload this extension immediately, removing any custom menu items etc., until the user refreshes the browser tab.
20
26
  */
@@ -75,6 +81,34 @@ class EditorClient {
75
81
  };
76
82
  });
77
83
  }
84
+ oauthXhr(providerName, request) {
85
+ return this.sendCommand("oauth" /* SendOAuthRequest */, {
86
+ 'url': request.url,
87
+ 'm': request.method,
88
+ 'd': request.data,
89
+ 'h': request.headers,
90
+ 'ms': request.timeoutMs,
91
+ 'p': providerName,
92
+ })
93
+ .then((raw) => {
94
+ return {
95
+ url: raw['url'],
96
+ responseText: raw['t'],
97
+ status: raw['s'],
98
+ headers: raw['h'],
99
+ timeout: raw['to'],
100
+ };
101
+ })
102
+ .catch((raw) => {
103
+ throw {
104
+ url: raw['url'],
105
+ responseText: raw['t'],
106
+ status: raw['s'],
107
+ headers: raw['h'],
108
+ timeout: raw['to'],
109
+ };
110
+ });
111
+ }
78
112
  /**
79
113
  * Register a named action. These actions can be triggered from custom UI, for example as the action of a
80
114
  * custom menu item.
@@ -196,6 +230,24 @@ class EditorClient {
196
230
  }
197
231
  return undefined;
198
232
  }
233
+ /**
234
+ * @param callback A callback that processes the bootstrap data, if any, stored on the document and
235
+ * associated with this editor extension. If this callback is async (returns a promise), then the
236
+ * bootstrap data is not cleared off of the document until that promise resolves.
237
+ *
238
+ * @return a promise that resolves immediately if there is no available bootstrap data, or else after
239
+ * the callback successfully completes. This promise will reject/throw if the callback throws or
240
+ * returns a promise that rejects, or if there is another editor session processing the same bootstrap
241
+ * data at the same time.
242
+ */
243
+ async processAndClearBootstrapData(callback) {
244
+ const name = this.getUniqueActionName();
245
+ this.registerAction(name, (msg) => {
246
+ return callback(msg['d']);
247
+ });
248
+ await this.sendCommand("b" /* Bootstrap */, { 'c': name });
249
+ this.deleteAction(name);
250
+ }
199
251
  /**
200
252
  * @param id ID of the line to create a proxy for
201
253
  * @returns the given line