@archilogic/extension-sdk 0.3.0 → 0.4.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @archilogic/extension-sdk
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 8532ccf: feat: rename onPluginConnect / Destroy to onConnect / Destroy
8
+
3
9
  ## 0.3.0
4
10
 
5
11
  ### Minor Changes
@@ -3,15 +3,15 @@ var Q = (e) => {
3
3
  throw TypeError(e);
4
4
  };
5
5
  var Ee = (e, t, r) => t in e ? we(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
6
- var P = (e, t, r) => Ee(e, typeof t != "symbol" ? t + "" : t, r), Z = (e, t, r) => t.has(e) || Q("Cannot " + r);
7
- var s = (e, t, r) => (Z(e, t, "read from private field"), r ? r.call(e) : t.get(e)), f = (e, t, r) => t.has(e) ? Q("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), I = (e, t, r, a) => (Z(e, t, "write to private field"), a ? a.call(e, r) : t.set(e, r), r);
8
- var Pe = class extends Error {
6
+ var I = (e, t, r) => Ee(e, typeof t != "symbol" ? t + "" : t, r), Z = (e, t, r) => t.has(e) || Q("Cannot " + r);
7
+ var s = (e, t, r) => (Z(e, t, "read from private field"), r ? r.call(e) : t.get(e)), f = (e, t, r) => t.has(e) ? Q("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, r), P = (e, t, r, a) => (Z(e, t, "write to private field"), a ? a.call(e, r) : t.set(e, r), r);
8
+ var Ie = class extends Error {
9
9
  constructor(t, r) {
10
10
  super(r);
11
- P(this, "code");
11
+ I(this, "code");
12
12
  this.name = "PenpalError", this.code = t;
13
13
  }
14
- }, w = Pe, Ie = (e) => ({
14
+ }, w = Ie, Pe = (e) => ({
15
15
  name: e.name,
16
16
  message: e.message,
17
17
  stack: e.stack,
@@ -26,15 +26,15 @@ var Pe = class extends Error {
26
26
  return n.name = e, n.stack = r, n;
27
27
  }, Se = Symbol("Reply"), B, ae, Ce = (ae = class {
28
28
  constructor(e, t) {
29
- P(this, "value");
30
- P(this, "transferables");
29
+ I(this, "value");
30
+ I(this, "transferables");
31
31
  // Allows TypeScript to distinguish between an actual instance of this
32
32
  // class versus an object that looks structurally similar.
33
33
  // eslint-disable-next-line no-unused-private-class-members
34
34
  f(this, B, Se);
35
35
  this.value = e, this.transferables = t == null ? void 0 : t.transferables;
36
36
  }
37
- }, B = new WeakMap(), ae), me = Ce, M = "penpal", W = (e) => typeof e == "object" && e !== null, ce = (e) => typeof e == "function", Re = (e) => W(e) && e.namespace === M, j = (e) => e.type === "SYN", X = (e) => e.type === "ACK1", z = (e) => e.type === "ACK2", de = (e) => e.type === "CALL", le = (e) => e.type === "REPLY", Ne = (e) => e.type === "DESTROY", ue = (e, t = []) => {
37
+ }, B = new WeakMap(), ae), me = Ce, M = "penpal", W = (e) => typeof e == "object" && e !== null, ce = (e) => typeof e == "function", Re = (e) => W(e) && e.namespace === M, j = (e) => e.type === "SYN", X = (e) => e.type === "ACK1", g = (e) => e.type === "ACK2", de = (e) => e.type === "CALL", le = (e) => e.type === "REPLY", Ne = (e) => e.type === "DESTROY", ue = (e, t = []) => {
38
38
  const r = [];
39
39
  for (const a of Object.keys(e)) {
40
40
  const n = e[a];
@@ -55,7 +55,7 @@ var Pe = class extends Error {
55
55
  type: "REPLY",
56
56
  callId: t,
57
57
  isError: !0,
58
- ...r instanceof Error ? { value: Ie(r), isSerializedErrorInstance: !0 } : { value: r }
58
+ ...r instanceof Error ? { value: Pe(r), isSerializedErrorInstance: !0 } : { value: r }
59
59
  }), Te = (e, t, r, a) => {
60
60
  let n = !1;
61
61
  const d = async (l) => {
@@ -96,8 +96,8 @@ var Pe = class extends Error {
96
96
  () => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)
97
97
  ).join("-")), Le = Symbol("CallOptions"), J, ie, ke = (ie = class {
98
98
  constructor(e) {
99
- P(this, "transferables");
100
- P(this, "timeout");
99
+ I(this, "transferables");
100
+ I(this, "timeout");
101
101
  // Allows TypeScript to distinguish between an actual instance of this
102
102
  // class versus an object that looks structurally similar.
103
103
  // eslint-disable-next-line no-unused-private-class-members
@@ -138,9 +138,9 @@ var Pe = class extends Error {
138
138
  remoteProxy: pe((h, o) => {
139
139
  if (a)
140
140
  throw te(h);
141
- const i = he(), E = o[o.length - 1], u = E instanceof be, { timeout: p, transferables: g } = u ? E : {}, F = u ? o.slice(0, -1) : o;
141
+ const i = he(), E = o[o.length - 1], u = E instanceof be, { timeout: p, transferables: K } = u ? E : {}, F = u ? o.slice(0, -1) : o;
142
142
  return new Promise((Y, O) => {
143
- const K = p !== void 0 ? window.setTimeout(() => {
143
+ const z = p !== void 0 ? window.setTimeout(() => {
144
144
  n.delete(i), O(
145
145
  new w(
146
146
  "METHOD_CALL_TIMEOUT",
@@ -150,7 +150,7 @@ var Pe = class extends Error {
150
150
  )
151
151
  );
152
152
  }, p) : void 0;
153
- n.set(i, { methodPath: h, resolve: Y, reject: O, timeoutId: K });
153
+ n.set(i, { methodPath: h, resolve: Y, reject: O, timeoutId: z });
154
154
  try {
155
155
  const T = {
156
156
  namespace: M,
@@ -160,7 +160,7 @@ var Pe = class extends Error {
160
160
  methodPath: h,
161
161
  args: F
162
162
  };
163
- r == null || r(`Sending ${C(h)}() call`, T), e.sendMessage(T, g);
163
+ r == null || r(`Sending ${C(h)}() call`, T), e.sendMessage(T, K);
164
164
  } catch (T) {
165
165
  O(
166
166
  new w("TRANSMISSION_FAILED", T.message)
@@ -271,7 +271,7 @@ var Pe = class extends Error {
271
271
  returnValue: e.value
272
272
  };
273
273
  throw fe(e);
274
- }, ge = ({
274
+ }, Ke = ({
275
275
  messenger: e,
276
276
  methods: t,
277
277
  timeout: r,
@@ -289,7 +289,7 @@ var Pe = class extends Error {
289
289
  `Connection timed out after ${r}ms`
290
290
  )
291
291
  );
292
- }, r) : void 0, g = () => {
292
+ }, r) : void 0, K = () => {
293
293
  for (const c of v)
294
294
  c();
295
295
  }, F = () => {
@@ -299,7 +299,7 @@ var Pe = class extends Error {
299
299
  const { remoteProxy: c, destroy: m } = xe(e, a, n);
300
300
  v.push(m), clearTimeout(p), h = !0, E({
301
301
  remoteProxy: c,
302
- destroy: g
302
+ destroy: K
303
303
  });
304
304
  }, Y = () => {
305
305
  const c = {
@@ -332,7 +332,7 @@ var Pe = class extends Error {
332
332
  u(new w("TRANSMISSION_FAILED", Me.message));
333
333
  return;
334
334
  }
335
- }, K = (c) => {
335
+ }, z = (c) => {
336
336
  n == null || n("Received handshake ACK1", c);
337
337
  const m = {
338
338
  namespace: M,
@@ -350,13 +350,13 @@ var Pe = class extends Error {
350
350
  }, T = (c) => {
351
351
  n == null || n("Received handshake ACK2", c), F();
352
352
  }, q = (c) => {
353
- j(c) && O(c), X(c) && K(c), z(c) && T(c);
353
+ j(c) && O(c), X(c) && z(c), g(c) && T(c);
354
354
  };
355
355
  return e.addMessageHandler(q), v.push(() => e.removeMessageHandler(q)), Y(), i;
356
- }, Ke = ge, ze = (e) => {
356
+ }, ze = Ke, ge = (e) => {
357
357
  let t = !1, r;
358
358
  return (...a) => (t || (t = !0, r = e(...a)), r);
359
- }, Ge = ze, ne = /* @__PURE__ */ new WeakSet(), Be = ({
359
+ }, Ge = ge, ne = /* @__PURE__ */ new WeakSet(), Be = ({
360
360
  messenger: e,
361
361
  methods: t = {},
362
362
  timeout: r,
@@ -393,7 +393,7 @@ var Pe = class extends Error {
393
393
  e.initialize({ log: n, validateReceivedMessage: v }), e.addMessageHandler((E) => {
394
394
  Ne(E) && l(!1);
395
395
  });
396
- const { remoteProxy: o, destroy: i } = await Ke({
396
+ const { remoteProxy: o, destroy: i } = await ze({
397
397
  messenger: e,
398
398
  methods: t,
399
399
  timeout: r,
@@ -422,13 +422,13 @@ var Pe = class extends Error {
422
422
  f(this, y);
423
423
  // TODO: Used for backward-compatibility. Remove in next major version.
424
424
  f(this, _, !1);
425
- P(this, "initialize", ({
425
+ I(this, "initialize", ({
426
426
  log: e,
427
427
  validateReceivedMessage: t
428
428
  }) => {
429
- I(this, D, e), I(this, L, t), window.addEventListener("message", s(this, x));
429
+ P(this, D, e), P(this, L, t), window.addEventListener("message", s(this, x));
430
430
  });
431
- P(this, "sendMessage", (e, t) => {
431
+ I(this, "sendMessage", (e, t) => {
432
432
  if (j(e)) {
433
433
  const r = s(this, k).call(this, e);
434
434
  s(this, A).postMessage(e, {
@@ -448,9 +448,9 @@ var Pe = class extends Error {
448
448
  });
449
449
  return;
450
450
  }
451
- if (z(e)) {
451
+ if (g(e)) {
452
452
  const { port1: r, port2: a } = new MessageChannel();
453
- I(this, y, r), r.addEventListener("message", s(this, b)), r.start();
453
+ P(this, y, r), r.addEventListener("message", s(this, b)), r.start();
454
454
  const n = [a, ...t || []], d = s(this, k).call(this, e);
455
455
  s(this, A).postMessage(e, {
456
456
  targetOrigin: d,
@@ -466,13 +466,13 @@ var Pe = class extends Error {
466
466
  }
467
467
  throw new U("Port is undefined");
468
468
  });
469
- P(this, "addMessageHandler", (e) => {
469
+ I(this, "addMessageHandler", (e) => {
470
470
  s(this, S).add(e);
471
471
  });
472
- P(this, "removeMessageHandler", (e) => {
472
+ I(this, "removeMessageHandler", (e) => {
473
473
  s(this, S).delete(e);
474
474
  });
475
- P(this, "destroy", () => {
475
+ I(this, "destroy", () => {
476
476
  window.removeEventListener("message", s(this, x)), s(this, H).call(this), s(this, S).clear();
477
477
  });
478
478
  f(this, V, (e) => s(this, R).some(
@@ -487,7 +487,7 @@ var Pe = class extends Error {
487
487
  });
488
488
  f(this, H, () => {
489
489
  var e, t;
490
- (e = s(this, y)) == null || e.removeEventListener("message", s(this, b)), (t = s(this, y)) == null || t.close(), I(this, y, void 0);
490
+ (e = s(this, y)) == null || e.removeEventListener("message", s(this, b)), (t = s(this, y)) == null || t.close(), P(this, y, void 0);
491
491
  });
492
492
  f(this, x, ({
493
493
  source: e,
@@ -499,7 +499,7 @@ var Pe = class extends Error {
499
499
  if (e === s(this, A) && (je(a) && ((n = s(this, D)) == null || n.call(
500
500
  this,
501
501
  "Please upgrade the child window to the latest version of Penpal."
502
- ), I(this, _, !0), a = Ve(a)), !!((d = s(this, L)) != null && d.call(this, a)))) {
502
+ ), P(this, _, !0), a = Ve(a)), !!((d = s(this, L)) != null && d.call(this, a)))) {
503
503
  if (!s(this, V).call(this, t)) {
504
504
  (l = s(this, D)) == null || l.call(
505
505
  this,
@@ -507,10 +507,10 @@ var Pe = class extends Error {
507
507
  );
508
508
  return;
509
509
  }
510
- if (j(a) && (s(this, H).call(this), I(this, N, t)), z(a) && // Previous versions of Penpal don't use MessagePorts and do all
510
+ if (j(a) && (s(this, H).call(this), P(this, N, t)), g(a) && // Previous versions of Penpal don't use MessagePorts and do all
511
511
  // communication through the window.
512
512
  !s(this, _)) {
513
- if (I(this, y, r[0]), !s(this, y))
513
+ if (P(this, y, r[0]), !s(this, y))
514
514
  throw new U("No port received on ACK2");
515
515
  s(this, y).addEventListener("message", s(this, b)), s(this, y).start();
516
516
  }
@@ -526,7 +526,7 @@ var Pe = class extends Error {
526
526
  });
527
527
  if (!e)
528
528
  throw new w("INVALID_ARGUMENT", "remoteWindow must be defined");
529
- I(this, A, e), I(this, R, t != null && t.length ? t : [window.origin]);
529
+ P(this, A, e), P(this, R, t != null && t.length ? t : [window.origin]);
530
530
  }
531
531
  }, A = new WeakMap(), R = new WeakMap(), D = new WeakMap(), L = new WeakMap(), N = new WeakMap(), S = new WeakMap(), y = new WeakMap(), _ = new WeakMap(), V = new WeakMap(), k = new WeakMap(), H = new WeakMap(), x = new WeakMap(), b = new WeakMap(), oe), ye = Je;
532
532
  const Qe = (e, t) => {
@@ -547,9 +547,13 @@ const Qe = (e, t) => {
547
547
  methods: t
548
548
  });
549
549
  }, Xe = {
550
- onPluginConnect: () => {
550
+ /**
551
+ * event handler for initial connection of the extension
552
+ * for a headless extension ( without UI ) the host will await this method before it terminates the extension
553
+ */
554
+ onConnect: () => {
551
555
  },
552
- onPluginDestroy: () => {
556
+ onDestroy: () => {
553
557
  },
554
558
  onLayoutChange: () => {
555
559
  },
package/dist/index.d.ts CHANGED
@@ -265,19 +265,20 @@ export declare type Connection<TMethods extends Methods = Methods> = {
265
265
 
266
266
  /**
267
267
  * @example
268
- * const pluginConnection = createPluginConnection(methods)
269
- * const pluginApi = await pluginConnection.promise
270
- * await pluginApi.onPluginConnect({ floorMetaData })
271
- * pluginConnection.destroy()
268
+ * const connection = createExtensionConnection(methods)
269
+ * const extension = await connection.promise
270
+ * // dispatch onConnect event
271
+ * await extension.onConnect({ floorMetaData })
272
+ * connection.destroy()
272
273
  */
273
274
  export declare const createExtensionConnection: (iframe: HTMLIFrameElement, methods: any) => Connection<ExtensionApi>;
274
275
 
275
276
  /**
276
277
  * @example
277
278
  * const hostApi = createHostConnection({
278
- * onPluginConnect: () => {}
279
+ * onConnect: () => {}
279
280
  * })
280
- * const spaceResponse = await hostApi.getSpaces()
281
+ * const spaces = await hostApi.getSpaces()
281
282
  */
282
283
  export declare const createHostConnection: (methods?: Partial<ExtensionApi>) => HostApi;
283
284
 
@@ -664,10 +665,10 @@ declare type EntityResult = {
664
665
  };
665
666
 
666
667
  export declare type ExtensionApi = {
667
- onPluginConnect({ floorMetaData }: {
668
+ onConnect({ floorMetaData }: {
668
669
  floorMetaData: any;
669
670
  }): void;
670
- onPluginDestroy(): void;
671
+ onDestroy(): void;
671
672
  onLayoutChange(args: any): void;
672
673
  onSelectionChange({ selectedNodes }: {
673
674
  selectedNodes: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@archilogic/extension-sdk",
3
3
  "description": "",
4
- "version": "0.3.0",
4
+ "version": "0.4.0",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },