lucid-extension-sdk 0.0.155 → 0.0.157

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/commandtypes.d.ts CHANGED
@@ -119,6 +119,8 @@ export declare const enum CommandName {
119
119
  UnhookDeleteItems = "udi",
120
120
  UnhookSelection = "us",
121
121
  UnhookTextEdit = "ute",
122
+ WithMutex = "wm",
123
+ WithSilentActions = "wsa",
122
124
  ZOrder = "z"
123
125
  }
124
126
  /** @ignore */
@@ -525,6 +527,14 @@ export declare type CommandArgs = {
525
527
  query: UnhookTextEditQuery;
526
528
  result: UnhookTextEditResult;
527
529
  };
530
+ [CommandName.WithMutex]: {
531
+ query: WithMutexQuery;
532
+ result: WithMutexResult;
533
+ };
534
+ [CommandName.WithSilentActions]: {
535
+ query: WithSilentActionsQuery;
536
+ result: WithSilentActionsResult;
537
+ };
528
538
  [CommandName.ZOrder]: {
529
539
  query: ZOrderQuery;
530
540
  result: ZOrderResult;
@@ -1281,6 +1291,19 @@ export declare type UnhookTextEditQuery = {
1281
1291
  'n': string;
1282
1292
  };
1283
1293
  export declare type UnhookTextEditResult = undefined;
1294
+ export declare type WithMutexQuery = {
1295
+ /** Name of the intra-document mutex to hold for the duration of this action */
1296
+ 'n': string;
1297
+ /** Name of the action to run within the given mutex */
1298
+ 'a': string;
1299
+ };
1300
+ /** Resolves true if operation succeeded, or false if the mutex was held by someone else */
1301
+ export declare type WithMutexResult = Promise<boolean>;
1302
+ export declare type WithSilentActionsQuery = {
1303
+ /** Name of the synchronous action to run with undo/redo history suppressed */
1304
+ 'a': string;
1305
+ };
1306
+ export declare type WithSilentActionsResult = void;
1284
1307
  export declare enum ZOrderOperation {
1285
1308
  UP = 1,
1286
1309
  TOP = 2,
package/commandtypes.js CHANGED
@@ -99,6 +99,8 @@ exports.commandTitles = new Map([
99
99
  ["udi" /* CommandName.UnhookDeleteItems */, 'UnhookDeleteItems'],
100
100
  ["us" /* CommandName.UnhookSelection */, 'UnhookSelection'],
101
101
  ["ute" /* CommandName.UnhookTextEdit */, 'UnhookTextEdit'],
102
+ ["wm" /* CommandName.WithMutex */, 'WithMutex'],
103
+ ["wsa" /* CommandName.WithSilentActions */, 'WithSilentActions'],
102
104
  ["z" /* CommandName.ZOrder */, 'ZOrder'],
103
105
  ]);
104
106
  var GetItemsAtSearchType;
package/editorclient.d.ts CHANGED
@@ -315,5 +315,22 @@ export declare class EditorClient {
315
315
  * @returns a Promise that resolves to a string if a user enters one, or undefined if they cancel
316
316
  */
317
317
  prompt(text: string, title?: string): import("./commandtypes").PromptResult;
318
+ /**
319
+ * Executes the given callback within a mutex scoped to the current document, extension, and the given name.
320
+ * If another editor session currently has the given mutex name locked within the same extension package ID
321
+ * on this same document, this function's returned promise will resolve to false. Otherwise, the mutex will
322
+ * be locked for the duration of the callback and the returned promise will resolve to true.
323
+ * @param name Name of the intra-document mutex to attempt to lock
324
+ * @param callback Code to execute while the mutex is locked, if it is successfully locked
325
+ * @returns A promise resolving to a boolean indicating whether the mutex was successfully locked
326
+ */
327
+ withIntraDocumentMutex(name: string, callback: () => void | Promise<void>): Promise<boolean>;
328
+ /**
329
+ * @param callback Callback that will be executed with the user's local undo/redo history suppressed. This is
330
+ * useful when you want to make changes to a document that will not be erased if the user uses undo or redo,
331
+ * for example adding shape data onto shapes as a result of a background process that collects data from a
332
+ * remote API.
333
+ */
334
+ withSilentActions(callback: () => void): void;
318
335
  constructor();
319
336
  }
package/editorclient.js CHANGED
@@ -529,5 +529,45 @@ class EditorClient {
529
529
  prompt(text, title) {
530
530
  return this.sendCommand("p" /* CommandName.Prompt */, { 't': title, 'b': text });
531
531
  }
532
+ /**
533
+ * Executes the given callback within a mutex scoped to the current document, extension, and the given name.
534
+ * If another editor session currently has the given mutex name locked within the same extension package ID
535
+ * on this same document, this function's returned promise will resolve to false. Otherwise, the mutex will
536
+ * be locked for the duration of the callback and the returned promise will resolve to true.
537
+ * @param name Name of the intra-document mutex to attempt to lock
538
+ * @param callback Code to execute while the mutex is locked, if it is successfully locked
539
+ * @returns A promise resolving to a boolean indicating whether the mutex was successfully locked
540
+ */
541
+ async withIntraDocumentMutex(name, callback) {
542
+ const action = this.getUniqueActionName();
543
+ this.registerAction(action, callback);
544
+ try {
545
+ return await this.sendCommand("wm" /* CommandName.WithMutex */, { 'n': name, 'a': action });
546
+ }
547
+ finally {
548
+ this.deleteAction(action);
549
+ }
550
+ }
551
+ /**
552
+ * @param callback Callback that will be executed with the user's local undo/redo history suppressed. This is
553
+ * useful when you want to make changes to a document that will not be erased if the user uses undo or redo,
554
+ * for example adding shape data onto shapes as a result of a background process that collects data from a
555
+ * remote API.
556
+ */
557
+ withSilentActions(callback) {
558
+ const action = this.getUniqueActionName();
559
+ this.registerAction(action, () => {
560
+ const result = callback();
561
+ if ((0, checks_1.isPromise)(result)) {
562
+ throw new Error('withSilentActions cannot be used with an async callback');
563
+ }
564
+ });
565
+ try {
566
+ this.sendCommand("wsa" /* CommandName.WithSilentActions */, { 'a': action });
567
+ }
568
+ finally {
569
+ this.deleteAction(action);
570
+ }
571
+ }
532
572
  }
533
573
  exports.EditorClient = EditorClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-extension-sdk",
3
- "version": "0.0.155",
3
+ "version": "0.0.157",
4
4
  "description": "Utility classes for writing Lucid Software editor extensions",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",