@syntrologie/adapt-chatbot 2.8.0-canary.550 → 2.8.0-canary.551

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.
@@ -199,13 +199,41 @@ export declare class LeaveAMessageLit extends LitElement {
199
199
  /** Snapshot {state, transcript, email} so the NEXT mount (a fresh page
200
200
  * in the same session) can pick the thread back up. */
201
201
  private _persist;
202
+ /** The pending reply announcement, if the canvas gave us a handle to it. */
203
+ private _noticeHandle;
202
204
  /**
203
- * Raise the reply toast through the canvas element. Pierces shadow roots to
205
+ * Is the visitor LOOKING at this card right now? True only when the card
206
+ * has a laid-out box inside the viewport, the document is visible, and a
207
+ * hit-test at the card's center lands on the card itself — so a deck card
208
+ * stacked behind another, a card under a maximized chat, or a closed
209
+ * canvas all read as "not on screen". The hit-test descends through open
210
+ * shadow roots (`document.elementFromPoint` stops at the outermost host).
211
+ * Canvas-agnostic on purpose: the card never asks a canvas which tile is
212
+ * front. Anything this can't evaluate (jsdom, no layout) is "not on
213
+ * screen": when unsure, announce — a missed reply costs more than an
214
+ * extra toast.
215
+ */
216
+ private _isOnScreen;
217
+ /** The tile id sc-mount stamps on every widget's container, so the card can
218
+ * name itself to the canvas when the visitor taps its announcement. */
219
+ private _instanceId;
220
+ /**
221
+ * Tap on the reply announcement: open the thread and ask the canvas to
222
+ * bring this tile to the front. `tile-recall` is the same composed event
223
+ * AdaptiveChatBar already raises for its own recalls — velvet cycles the
224
+ * deck to the card and un-maximizes the chat; the host opens the canvas
225
+ * if it was closed.
226
+ */
227
+ private _recall;
228
+ /**
229
+ * Announce a reply through the canvas element. Pierces shadow roots to
204
230
  * find `<smart-canvas>` (same resolution AdaptiveChatBarMountable uses), and
205
231
  * no-ops when no canvas is present — the tile's own "You got mail!" face is
206
- * always the durable signal.
232
+ * always the durable signal. The announcement is PERSISTENT: a human's
233
+ * reply is the one thing the visitor was waiting on, so it stays until
234
+ * tapped or until the visitor opens the thread themselves (`_flip`).
207
235
  */
208
- private _toastReplyArrived;
236
+ private _announceReply;
209
237
  /** Paint our own focus ring from the theme. The border now lives on the
210
238
  * field SHELL (`data-lam-field-wrap`), not the borderless inner
211
239
  * textarea/input, so the ring targets that ancestor via `closest()`. */
@@ -1 +1 @@
1
- {"version":3,"file":"LeaveAMessageLit.d.ts","sourceRoot":"","sources":["../src/LeaveAMessageLit.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,OAAO,EAAQ,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAGhD,OAAO,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAgR9D,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;AAEhF;;;;;;;;;GASG;AACH,MAAM,WAAW,iBAAiB;IAChC;0EACsE;IACtE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;iEAC6D;IAC7D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;+DAC2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;0BACsB;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;uCACmC;IACnC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;oCAEgC;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,wDAAwD;IACxD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,8DAA8D;IAC9D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;uC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AIf;IAEF,OAAO,CAAC,QAAQ,CAmCd;IAEF;;;;;iDAK6C;IAC7C,OAAO,CAAC,cAAc,CAQpB;IAEF;;gFAE4E;IAC5E,OAAO,CAAC,YAAY,CAQlB;IAEF;;;8BAG0B;IAC1B,OAAO,CAAC,UAAU,CAIhB;IAEF,OAAO,CAAC,KAAK,CAQX;IAEF;;;;;;sCAMkC;IAClC,OAAO,CAAC,cAAc;IAStB,OAAO,CAAC,UAAU,CAWhB;IAEF,2EAA2E;IAC3E,OAAO,CAAC,gBAAgB;IAIxB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,OAAO,CAAC,UAAU,CAKhB;IAEO,MAAM;CAiNhB;AAED,wEAAwE;AACxE,wBAAgB,wBAAwB,IAAI,IAAI,CAI/C"}
package/dist/runtime.js CHANGED
@@ -2741,6 +2741,21 @@ var LeaveAMessageLit = class extends LitElement {
2741
2741
  * 'flipped' branch). Seeded with the visitor's own compose-step message
2742
2742
  * in `_submitMessage`. */
2743
2743
  this._transcript = [];
2744
+ /**
2745
+ * Tap on the reply announcement: open the thread and ask the canvas to
2746
+ * bring this tile to the front. `tile-recall` is the same composed event
2747
+ * AdaptiveChatBar already raises for its own recalls — velvet cycles the
2748
+ * deck to the card and un-maximizes the chat; the host opens the canvas
2749
+ * if it was closed.
2750
+ */
2751
+ this._recall = () => {
2752
+ this._flip();
2753
+ const instanceId = this._instanceId();
2754
+ if (!instanceId) return;
2755
+ this.dispatchEvent(
2756
+ new CustomEvent("tile-recall", { bubbles: true, composed: true, detail: { instanceId } })
2757
+ );
2758
+ };
2744
2759
  /** Paint our own focus ring from the theme. The border now lives on the
2745
2760
  * field SHELL (`data-lam-field-wrap`), not the borderless inner
2746
2761
  * textarea/input, so the ring targets that ancestor via `closest()`. */
@@ -2757,10 +2772,10 @@ var LeaveAMessageLit = class extends LitElement {
2757
2772
  };
2758
2773
  this._onReply = (text) => {
2759
2774
  this._transcript = [...this._transcript, { role: "operator", text }];
2775
+ const reading = this.state === "flipped" && this._isOnScreen();
2760
2776
  if (this.state !== "flipped") {
2761
2777
  this.state = "mail";
2762
2778
  this.runtime?.events.publish("supportchat:reply_received", { text });
2763
- this._toastReplyArrived();
2764
2779
  this.dispatchEvent(
2765
2780
  new CustomEvent("syntro:supportchat-reply", {
2766
2781
  bubbles: true,
@@ -2769,6 +2784,7 @@ var LeaveAMessageLit = class extends LitElement {
2769
2784
  })
2770
2785
  );
2771
2786
  }
2787
+ if (!reading) this._announceReply();
2772
2788
  this._persist();
2773
2789
  this.requestUpdate();
2774
2790
  };
@@ -2812,6 +2828,8 @@ var LeaveAMessageLit = class extends LitElement {
2812
2828
  this._flip = () => {
2813
2829
  this.state = "flipped";
2814
2830
  this._touched = false;
2831
+ this._noticeHandle?.dismiss();
2832
+ this._noticeHandle = void 0;
2815
2833
  this._persist();
2816
2834
  };
2817
2835
  this._sendReply = () => {
@@ -2870,6 +2888,8 @@ var LeaveAMessageLit = class extends LitElement {
2870
2888
  this.removeEventListener("keydown", this._onKeyDown);
2871
2889
  this._unsubscribe?.();
2872
2890
  this._unsubscribe = void 0;
2891
+ this._noticeHandle?.dismiss();
2892
+ this._noticeHandle = void 0;
2873
2893
  super.disconnectedCallback();
2874
2894
  }
2875
2895
  /** Read the injected persistence store, if any (I2). */
@@ -2898,12 +2918,53 @@ var LeaveAMessageLit = class extends LitElement {
2898
2918
  store.set(PERSIST_KEY, snapshot);
2899
2919
  }
2900
2920
  /**
2901
- * Raise the reply toast through the canvas element. Pierces shadow roots to
2921
+ * Is the visitor LOOKING at this card right now? True only when the card
2922
+ * has a laid-out box inside the viewport, the document is visible, and a
2923
+ * hit-test at the card's center lands on the card itself — so a deck card
2924
+ * stacked behind another, a card under a maximized chat, or a closed
2925
+ * canvas all read as "not on screen". The hit-test descends through open
2926
+ * shadow roots (`document.elementFromPoint` stops at the outermost host).
2927
+ * Canvas-agnostic on purpose: the card never asks a canvas which tile is
2928
+ * front. Anything this can't evaluate (jsdom, no layout) is "not on
2929
+ * screen": when unsure, announce — a missed reply costs more than an
2930
+ * extra toast.
2931
+ */
2932
+ _isOnScreen() {
2933
+ if (typeof document === "undefined" || typeof window === "undefined") return false;
2934
+ if (document.visibilityState !== "visible") return false;
2935
+ const r = this.getBoundingClientRect();
2936
+ if (r.width <= 0 || r.height <= 0) return false;
2937
+ const cx = r.left + r.width / 2;
2938
+ const cy = r.top + r.height / 2;
2939
+ if (cx < 0 || cy < 0 || cx > window.innerWidth || cy > window.innerHeight) return false;
2940
+ if (typeof document.elementFromPoint !== "function") return false;
2941
+ let hit = document.elementFromPoint(cx, cy);
2942
+ while (hit?.shadowRoot && typeof hit.shadowRoot.elementFromPoint === "function") {
2943
+ const inner = hit.shadowRoot.elementFromPoint(cx, cy);
2944
+ if (!inner || inner === hit) break;
2945
+ hit = inner;
2946
+ }
2947
+ let node = hit;
2948
+ while (node) {
2949
+ if (node === this) return true;
2950
+ node = node.parentNode ?? node.host ?? null;
2951
+ }
2952
+ return false;
2953
+ }
2954
+ /** The tile id sc-mount stamps on every widget's container, so the card can
2955
+ * name itself to the canvas when the visitor taps its announcement. */
2956
+ _instanceId() {
2957
+ return this.closest("[data-tile-id]")?.getAttribute("data-tile-id") ?? void 0;
2958
+ }
2959
+ /**
2960
+ * Announce a reply through the canvas element. Pierces shadow roots to
2902
2961
  * find `<smart-canvas>` (same resolution AdaptiveChatBarMountable uses), and
2903
2962
  * no-ops when no canvas is present — the tile's own "You got mail!" face is
2904
- * always the durable signal.
2963
+ * always the durable signal. The announcement is PERSISTENT: a human's
2964
+ * reply is the one thing the visitor was waiting on, so it stays until
2965
+ * tapped or until the visitor opens the thread themselves (`_flip`).
2905
2966
  */
2906
- _toastReplyArrived() {
2967
+ _announceReply() {
2907
2968
  if (typeof document === "undefined") return;
2908
2969
  const title = this.replyToast?.title?.trim();
2909
2970
  if (!title) return;
@@ -2921,7 +2982,15 @@ var LeaveAMessageLit = class extends LitElement {
2921
2982
  };
2922
2983
  try {
2923
2984
  const canvas = find(document);
2924
- canvas?.previewNotification?.({ title, body: this.replyToast?.body });
2985
+ this._noticeHandle?.dismiss();
2986
+ this._noticeHandle = void 0;
2987
+ const handle = canvas?.previewNotification?.({
2988
+ title,
2989
+ body: this.replyToast?.body,
2990
+ persistent: true,
2991
+ onTap: this._recall
2992
+ });
2993
+ if (handle && typeof handle.dismiss === "function") this._noticeHandle = handle;
2925
2994
  } catch (err) {
2926
2995
  console.warn("supportChat.widget: reply toast failed", err);
2927
2996
  }