@xpert-ai/chatkit-web-component 0.3.2 → 0.3.4

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.
@@ -47,7 +47,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
47
47
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
48
48
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
49
49
  var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
50
- var _a, _b, _setTrainingOptOut_dec, _hideHistory_dec, _showHistory_dec, _sendCustomAction_dec, _shareThread_dec, _setThreadId_dec, _setComposerValue_dec, _sendUserMessage_dec, _fetchUpdates_dec, _focusComposer_dec, _c, _opts, _frameUrl, _frame, _wrapper, _launcherCloseButton, _launcherOpen, _framePetOptionsOverride, _petClosedByContextMenu, _shadow, _petOverlay, _resolveLoaded, _loaded, _messenger, _ChatKitElementBase_instances, emitAndThrow_fn, setOptionsDataAttributes_fn, getDisplayMode_fn, getConfiguredPetOptions_fn, getOverlayPetOptions_fn, resolvePetAssetUrl_fn, resolveOverlayPetOptions_fn, getFrameOptions_fn, setLauncherOpen_fn, handlePetActivate_fn, handlePetClose_fn, handlePetReply_fn, handlePetThreadSummaryActivate_fn, _handleLauncherClose, getFrameUrl_fn, setFrameUrl_fn, consumeFrameUrl_fn, _handleFrameLoad, _initialized, maybeInit_fn, _init;
50
+ var _a, _b, _setTrainingOptOut_dec, _hideHistory_dec, _showHistory_dec, _sendCustomAction_dec, _shareThread_dec, _setThreadId_dec, _setComposerValue_dec, _sendUserMessage_dec, _fetchUpdates_dec, _focusComposer_dec, _c, _opts, _frameUrl, _frame, _wrapper, _launcherCloseButton, _launcherOpen, _chatMinimizedToPet, _framePetOptionsOverride, _petClosedByContextMenu, _shadow, _petOverlay, _resolveLoaded, _loaded, _messenger, _ChatKitElementBase_instances, emitAndThrow_fn, setOptionsDataAttributes_fn, getDisplayMode_fn, getConfiguredPetOptions_fn, mergeConfiguredPetPositionDefaults_fn, getOverlayPetOptions_fn, resolvePetAssetUrl_fn, resolveOverlayPetOptions_fn, getFrameOptions_fn, setLauncherOpen_fn, setChatMinimizedToPet_fn, syncPetOverlayOptions_fn, handlePetActivate_fn, handlePetClose_fn, handlePetReply_fn, handlePetThreadSummaryActivate_fn, _handleLauncherClose, getFrameUrl_fn, setFrameUrl_fn, consumeFrameUrl_fn, _handleFrameLoad, _initialized, maybeInit_fn, _init;
51
51
  class EventEmitter {
52
52
  constructor() {
53
53
  __publicField(this, "callbacks", /* @__PURE__ */ new Map());
@@ -2494,6 +2494,7 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2494
2494
  __privateAdd(this, _wrapper);
2495
2495
  __privateAdd(this, _launcherCloseButton);
2496
2496
  __privateAdd(this, _launcherOpen, false);
2497
+ __privateAdd(this, _chatMinimizedToPet, false);
2497
2498
  __privateAdd(this, _framePetOptionsOverride);
2498
2499
  __privateAdd(this, _petClosedByContextMenu, false);
2499
2500
  __privateAdd(this, _shadow, this.attachShadow({ mode: "open" }));
@@ -2630,6 +2631,9 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2630
2631
  :host([data-display-mode="pet"]) {
2631
2632
  display: contents;
2632
2633
  }
2634
+ :host([data-chat-minimized-to-pet="true"]) {
2635
+ display: contents;
2636
+ }
2633
2637
  .ck-iframe {
2634
2638
  border: none;
2635
2639
  position: absolute;
@@ -2740,6 +2744,11 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2740
2744
  :host([data-loaded="true"]) .ck-wrapper {
2741
2745
  opacity: 1;
2742
2746
  }
2747
+ :host([data-chat-minimized-to-pet="true"]) .ck-wrapper {
2748
+ opacity: 0;
2749
+ pointer-events: none;
2750
+ visibility: hidden;
2751
+ }
2743
2752
  :host([data-display-mode="pet"]:not([data-chat-open="true"])) .ck-wrapper {
2744
2753
  opacity: 0;
2745
2754
  }
@@ -2826,7 +2835,17 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2826
2835
  __privateSet(this, _petClosedByContextMenu, false);
2827
2836
  }
2828
2837
  __privateSet(this, _framePetOptionsOverride, payload.pet);
2829
- __privateGet(this, _petOverlay).setOptions(__privateMethod(this, _ChatKitElementBase_instances, getOverlayPetOptions_fn).call(this));
2838
+ __privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
2839
+ }
2840
+ });
2841
+ __privateGet(this, _messenger).on("chat_minimize_change", (data) => {
2842
+ const minimized = typeof data === "object" && data !== null && "minimized" in data && data.minimized === true;
2843
+ if (minimized && !__privateMethod(this, _ChatKitElementBase_instances, getOverlayPetOptions_fn).call(this)) {
2844
+ return;
2845
+ }
2846
+ __privateMethod(this, _ChatKitElementBase_instances, setChatMinimizedToPet_fn).call(this, minimized);
2847
+ if (minimized) {
2848
+ __privateMethod(this, _ChatKitElementBase_instances, setLauncherOpen_fn).call(this, false);
2830
2849
  }
2831
2850
  });
2832
2851
  __privateGet(this, _messenger).on("unmount", () => {
@@ -2864,7 +2883,7 @@ class ChatKitElementBase extends (_c = HTMLElement, _focusComposer_dec = [requir
2864
2883
  __privateSet(this, _opts, newOptions);
2865
2884
  __privateSet(this, _petClosedByContextMenu, false);
2866
2885
  __privateGet(this, _petOverlay).setLocale(newOptions.locale);
2867
- __privateGet(this, _petOverlay).setOptions(__privateMethod(this, _ChatKitElementBase_instances, getOverlayPetOptions_fn).call(this));
2886
+ __privateMethod(this, _ChatKitElementBase_instances, syncPetOverlayOptions_fn).call(this);
2868
2887
  if (__privateGet(this, _initialized)) {
2869
2888
  __privateMethod(this, _ChatKitElementBase_instances, setOptionsDataAttributes_fn).call(this, __privateGet(this, _opts));
2870
2889
  __privateGet(this, _loaded).then(() => {
@@ -2944,6 +2963,7 @@ _frame = new WeakMap();
2944
2963
  _wrapper = new WeakMap();
2945
2964
  _launcherCloseButton = new WeakMap();
2946
2965
  _launcherOpen = new WeakMap();
2966
+ _chatMinimizedToPet = new WeakMap();
2947
2967
  _framePetOptionsOverride = new WeakMap();
2948
2968
  _petClosedByContextMenu = new WeakMap();
2949
2969
  _shadow = new WeakMap();
@@ -2976,11 +2996,42 @@ getConfiguredPetOptions_fn = function(options = __privateGet(this, _opts)) {
2976
2996
  }
2977
2997
  return options.pet ?? null;
2978
2998
  };
2999
+ mergeConfiguredPetPositionDefaults_fn = function(pet) {
3000
+ if (!pet) {
3001
+ return pet;
3002
+ }
3003
+ const configured = normalizePetOptions(
3004
+ __privateMethod(this, _ChatKitElementBase_instances, getConfiguredPetOptions_fn).call(this) ?? null
3005
+ );
3006
+ if (!configured) {
3007
+ return pet;
3008
+ }
3009
+ if (pet === true) {
3010
+ return { position: configured.position };
3011
+ }
3012
+ if (!pet.position) {
3013
+ return { ...pet, position: configured.position };
3014
+ }
3015
+ return {
3016
+ ...pet,
3017
+ position: {
3018
+ ...configured.position,
3019
+ ...pet.position,
3020
+ boundsPadding: pet.position.boundsPadding ?? configured.position.boundsPadding,
3021
+ pin: "pin" in pet.position ? pet.position.pin : configured.position.pin
3022
+ }
3023
+ };
3024
+ };
2979
3025
  getOverlayPetOptions_fn = function() {
2980
3026
  if (__privateGet(this, _petClosedByContextMenu)) {
2981
3027
  return null;
2982
3028
  }
2983
- let pet = __privateGet(this, _framePetOptionsOverride) !== void 0 ? __privateGet(this, _framePetOptionsOverride) : __privateMethod(this, _ChatKitElementBase_instances, getConfiguredPetOptions_fn).call(this);
3029
+ let pet;
3030
+ if (__privateGet(this, _framePetOptionsOverride) !== void 0) {
3031
+ pet = __privateMethod(this, _ChatKitElementBase_instances, mergeConfiguredPetPositionDefaults_fn).call(this, __privateGet(this, _framePetOptionsOverride));
3032
+ } else {
3033
+ pet = __privateMethod(this, _ChatKitElementBase_instances, getConfiguredPetOptions_fn).call(this);
3034
+ }
2984
3035
  if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) === "pet" && !normalizePetOptions(pet ?? null)) {
2985
3036
  pet = true;
2986
3037
  }
@@ -3034,7 +3085,31 @@ setLauncherOpen_fn = function(open) {
3034
3085
  delete this.dataset.chatOpen;
3035
3086
  }
3036
3087
  };
3088
+ setChatMinimizedToPet_fn = function(minimized) {
3089
+ const next = minimized && Boolean(__privateMethod(this, _ChatKitElementBase_instances, getOverlayPetOptions_fn).call(this));
3090
+ __privateSet(this, _chatMinimizedToPet, next);
3091
+ if (next) {
3092
+ this.dataset.chatMinimizedToPet = "true";
3093
+ } else {
3094
+ delete this.dataset.chatMinimizedToPet;
3095
+ }
3096
+ };
3097
+ syncPetOverlayOptions_fn = function() {
3098
+ const overlayPetOptions = __privateMethod(this, _ChatKitElementBase_instances, getOverlayPetOptions_fn).call(this);
3099
+ __privateGet(this, _petOverlay).setOptions(overlayPetOptions);
3100
+ if (!overlayPetOptions) {
3101
+ __privateMethod(this, _ChatKitElementBase_instances, setChatMinimizedToPet_fn).call(this, false);
3102
+ }
3103
+ };
3037
3104
  handlePetActivate_fn = function() {
3105
+ if (__privateGet(this, _chatMinimizedToPet)) {
3106
+ __privateMethod(this, _ChatKitElementBase_instances, setChatMinimizedToPet_fn).call(this, false);
3107
+ if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) === "pet") {
3108
+ __privateMethod(this, _ChatKitElementBase_instances, setLauncherOpen_fn).call(this, true);
3109
+ }
3110
+ __privateGet(this, _loaded).then(() => this.focusComposer()).catch(() => void 0);
3111
+ return;
3112
+ }
3038
3113
  if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) !== "pet") {
3039
3114
  return;
3040
3115
  }
@@ -3044,6 +3119,7 @@ handlePetActivate_fn = function() {
3044
3119
  handlePetClose_fn = function() {
3045
3120
  __privateSet(this, _petClosedByContextMenu, true);
3046
3121
  __privateSet(this, _framePetOptionsOverride, null);
3122
+ __privateMethod(this, _ChatKitElementBase_instances, setChatMinimizedToPet_fn).call(this, false);
3047
3123
  __privateMethod(this, _ChatKitElementBase_instances, setLauncherOpen_fn).call(this, false);
3048
3124
  __privateGet(this, _petOverlay).setOptions(null);
3049
3125
  if (__privateMethod(this, _ChatKitElementBase_instances, getDisplayMode_fn).call(this) === "pet") {