lucid-extension-sdk 0.0.246 → 0.0.247

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
@@ -1429,8 +1429,14 @@ export type RegisterPanelResult = undefined;
1429
1429
  export type RegisterUnfurlQuery = {
1430
1430
  /** Domain to unfurl, e.g. www.google.com */
1431
1431
  'd': string;
1432
- /** Action to call to configure the unfurl */
1433
- 'a': string;
1432
+ /** For backwards compatility */
1433
+ 'a'?: string | undefined;
1434
+ /** Unfurl Action name for the unfurl handler */
1435
+ 'ua'?: string | undefined;
1436
+ /** After Unfurl Action name for the unfurl handler */
1437
+ 'aua'?: string | undefined;
1438
+ /** Expand Callback Action name for the unfurl handler */
1439
+ 'e'?: string | undefined;
1434
1440
  };
1435
1441
  export type RegisterUnfurlResult = boolean;
1436
1442
  export type ReloadExtensionQuery = void;
@@ -3,7 +3,8 @@ import { UnfurlDetails } from './unfurldetails';
3
3
  import { UnfurlRefreshErrorType } from './unfurlrefresherrortype';
4
4
  export declare enum UnfurlCallbackType {
5
5
  Unfurl = "u",
6
- AfterUnfurl = "a"
6
+ AfterUnfurl = "a",
7
+ ExpandCallback = "e"
7
8
  }
8
9
  /**
9
10
  * The callbacks that handle unfurls and refreshing.
@@ -33,4 +34,12 @@ export interface UnfurlCallbacks {
33
34
  * @param blockProxy The block proxy of the unfurl block
34
35
  */
35
36
  afterUnfurlCallback?: (blockProxy: LinkUnfurlBlockProxy, url: string) => Promise<void>;
37
+ /**
38
+ * Callback upon clicking expand button.
39
+ * Occurs before attempting to expand iframe.
40
+ *
41
+ * @param blockProxy The block proxy of the unfurl block
42
+ * @param url The url to unfurl
43
+ */
44
+ expandCallback?: (blockProxy: LinkUnfurlBlockProxy, url: string) => Promise<void>;
36
45
  }
@@ -5,4 +5,5 @@ var UnfurlCallbackType;
5
5
  (function (UnfurlCallbackType) {
6
6
  UnfurlCallbackType["Unfurl"] = "u";
7
7
  UnfurlCallbackType["AfterUnfurl"] = "a";
8
+ UnfurlCallbackType["ExpandCallback"] = "e";
8
9
  })(UnfurlCallbackType || (exports.UnfurlCallbackType = UnfurlCallbackType = {}));
@@ -39,6 +39,10 @@ export declare class LinkUnfurlBlockProxy extends BlockProxy {
39
39
  * Sets the URL to be loaded in an iframe when the user clicks the "Expand" action on the block.
40
40
  */
41
41
  setIframe(unfurlIframe: UnfurlIframe): void;
42
+ /**
43
+ * Returns true if there is an iframe URL already set for this unfurl block
44
+ */
45
+ hasIframe(): boolean;
42
46
  /**
43
47
  * Sets the main thumbnail on the block
44
48
  */
@@ -60,6 +60,12 @@ class LinkUnfurlBlockProxy extends blockproxy_1.BlockProxy {
60
60
  this.properties.set('LinkUnfurlIframeHeight', iframeAttributes.height);
61
61
  this.properties.set('LinkUnfurlIframeWidth', iframeAttributes.width);
62
62
  }
63
+ /**
64
+ * Returns true if there is an iframe URL already set for this unfurl block
65
+ */
66
+ hasIframe() {
67
+ return !!this.properties.get('LinkUnfurlIframeHtml');
68
+ }
63
69
  /**
64
70
  * Sets the main thumbnail on the block
65
71
  */
package/editorclient.js CHANGED
@@ -4,7 +4,6 @@ exports.EditorClient = void 0;
4
4
  const commandtypes_1 = require("./commandtypes");
5
5
  const base64_1 = require("./core/base64");
6
6
  const checks_1 = require("./core/checks");
7
- const unfurlcallbacks_1 = require("./core/unfurl/unfurlcallbacks");
8
7
  const unfurldetails_1 = require("./core/unfurl/unfurldetails");
9
8
  const unfurlrefresherrortype_1 = require("./core/unfurl/unfurlrefresherrortype");
10
9
  const collectionproxy_1 = require("./data/collectionproxy");
@@ -318,36 +317,55 @@ class EditorClient {
318
317
  * @param callbacks The callbacks to call when a link matching the domain is pasted.
319
318
  */
320
319
  registerUnfurlHandler(domain, callbacks) {
321
- const action = this.getUniqueActionName();
322
- this.registerAction(action, async (rawMsg) => {
323
- var _a;
320
+ const unfurlAction = this.getUniqueActionName();
321
+ let afterUnfurlAction = undefined;
322
+ let expandAction = undefined;
323
+ this.registerAction(unfurlAction, async (rawMsg) => {
324
324
  const msg = (0, unfurleventmessage_1.deserializeUnfurlEventMessage)(rawMsg);
325
- switch (msg.unfurlCallbackType) {
326
- case unfurlcallbacks_1.UnfurlCallbackType.Unfurl: {
327
- try {
328
- const result = await callbacks.unfurlCallback(msg.url);
329
- if (result && !(0, unfurlrefresherrortype_1.unfurlRefreshErrorTypeValidator)(result)) {
330
- return (0, unfurldetails_1.serializeUnfurlDetails)(result);
331
- }
332
- }
333
- catch (err) {
334
- return unfurlrefresherrortype_1.UnfurlRefreshErrorType.GenericFailure;
325
+ try {
326
+ const result = await callbacks.unfurlCallback(msg.url);
327
+ if (result && !(0, unfurlrefresherrortype_1.unfurlRefreshErrorTypeValidator)(result)) {
328
+ return (0, unfurldetails_1.serializeUnfurlDetails)(result);
329
+ }
330
+ }
331
+ catch (err) {
332
+ return unfurlrefresherrortype_1.UnfurlRefreshErrorType.GenericFailure;
333
+ }
334
+ return undefined;
335
+ });
336
+ if (callbacks.afterUnfurlCallback) {
337
+ afterUnfurlAction = this.getUniqueActionName();
338
+ this.registerAction(afterUnfurlAction, async (rawMsg) => {
339
+ var _a;
340
+ const msg = (0, unfurleventmessage_1.deserializeUnfurlEventMessage)(rawMsg);
341
+ if (msg.blockId) {
342
+ const proxy = this.getBlockProxy(msg.blockId);
343
+ if (proxy instanceof linkunfurlblockproxy_1.LinkUnfurlBlockProxy) {
344
+ await ((_a = callbacks.afterUnfurlCallback) === null || _a === void 0 ? void 0 : _a.call(callbacks, proxy, msg.url));
335
345
  }
336
- break;
337
346
  }
338
- case unfurlcallbacks_1.UnfurlCallbackType.AfterUnfurl: {
339
- if (msg.blockId) {
340
- const proxy = this.getBlockProxy(msg.blockId);
341
- if (proxy instanceof linkunfurlblockproxy_1.LinkUnfurlBlockProxy) {
342
- await ((_a = callbacks.afterUnfurlCallback) === null || _a === void 0 ? void 0 : _a.call(callbacks, proxy, msg.url));
343
- }
347
+ return undefined;
348
+ });
349
+ }
350
+ if (callbacks.expandCallback) {
351
+ expandAction = this.getUniqueActionName();
352
+ this.registerAction(expandAction, async (rawMsg) => {
353
+ var _a;
354
+ const msg = (0, unfurleventmessage_1.deserializeUnfurlEventMessage)(rawMsg);
355
+ if (msg.blockId) {
356
+ const proxy = this.getBlockProxy(msg.blockId);
357
+ if (proxy instanceof linkunfurlblockproxy_1.LinkUnfurlBlockProxy) {
358
+ await ((_a = callbacks.expandCallback) === null || _a === void 0 ? void 0 : _a.call(callbacks, proxy, msg.url));
344
359
  }
345
- break;
346
360
  }
347
- }
348
- return undefined;
361
+ });
362
+ }
363
+ this.sendCommand("ru" /* CommandName.RegisterUnfurl */, {
364
+ 'd': domain,
365
+ 'ua': unfurlAction,
366
+ 'aua': afterUnfurlAction,
367
+ 'e': expandAction,
349
368
  });
350
- this.sendCommand("ru" /* CommandName.RegisterUnfurl */, { 'd': domain, 'a': action });
351
369
  }
352
370
  /**
353
371
  * @ignore
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lucid-extension-sdk",
3
- "version": "0.0.246",
3
+ "version": "0.0.247",
4
4
  "description": "Utility classes for writing Lucid Software editor extensions",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",