@wexio/messenger-widget-ember 1.5.3 → 1.6.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
  # @wexio/messenger-widget-ember
2
2
 
3
+ ## 1.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - cdbf505: Open-state and navigation props on every embed: `defaultOpen`, controlled `open` and `previewTab` (React props, web-component `default-open` / `open` attributes and `previewTab` property, Vue / Angular / Ember wrappers, and `Wexio('open' | 'close' | 'navigate')` + `wexioSettings.defaultOpen` for the script tag). New integration-level `theme.launcherOffset` (px, clamped 0..200) moves the launcher, peek and panel in all three embeds; a host offset wins. Fixes: a persisted `sending` outbox op is retried after a reload, and Enter that confirms an IME candidate no longer sends the message.
8
+
3
9
  ## 1.5.3
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -161,6 +161,10 @@ Service API:
161
161
  | `show()` | Show the widget panel. |
162
162
  | `hide()` | Hide the widget panel. |
163
163
  | `shutdown()` | Clear identity (log out). |
164
+ | `open()` / `close()` | Open / close the panel (sets the element's `open` attribute; falls back to `window.Wexio('open' \| 'close')`). |
165
+ | `navigate({ tab, article? })` | Go to a tab / help article / news post without a remount; opens the panel (sets the element's `previewTab`). |
166
+
167
+ In a template you can also set `default-open="true"` and `open="true"` / `open="false"` (strings; a boolean `false` would remove the attribute and leave the widget uncontrolled) on `<wexio-widget>`.
164
168
 
165
169
  ## Types
166
170
 
package/dist/index.cjs CHANGED
@@ -32,6 +32,9 @@ function ensureRuntime() {
32
32
  document.head.appendChild(script);
33
33
  }
34
34
 
35
+ /** Monotonic nonce so every `navigate()` is a new request. */
36
+ let navNonce = 0;
37
+
35
38
  class WexioWidgetService {
36
39
  constructor() {
37
40
  ensureRuntime();
@@ -68,6 +71,50 @@ class WexioWidgetService {
68
71
  if (typeof window === "undefined") return;
69
72
  if (typeof window.Wexio === "function") window.Wexio("shutdown");
70
73
  }
74
+
75
+ /** Open the panel (the widget element's controlled `open`, else the loader command). */
76
+ open() {
77
+ this._setOpen(true);
78
+ }
79
+
80
+ /** Close the panel. */
81
+ close() {
82
+ this._setOpen(false);
83
+ }
84
+
85
+ /**
86
+ * Navigate to a tab (and optionally a help article / news post) without a remount; opens the
87
+ * panel. `{ tab, article? }`; every call is a new request.
88
+ */
89
+ navigate(target) {
90
+ const el = this.element;
91
+ if (el) {
92
+ navNonce += 1;
93
+ el.previewTab = { ...target, nonce: navNonce };
94
+ } else if (typeof window !== "undefined" && typeof window.Wexio === "function") {
95
+ window.Wexio("navigate", target);
96
+ }
97
+ }
98
+
99
+ _setOpen(open) {
100
+ const el = this.element;
101
+ if (el) {
102
+ const want = open ? "true" : "false";
103
+ // Idempotent: already in the wanted state (read from the rendered panel) -> nothing to do.
104
+ const panel = el.shadowRoot && el.shadowRoot.querySelector("[data-wx-panel]");
105
+ if (panel && !panel.hasAttribute("inert") === open) return;
106
+ // The widget reacts to the attribute CHANGING. It already says `want` but the panel is not
107
+ // there (the visitor toggled it since): flip it away first so this call is a transition again.
108
+ if (el.getAttribute("open") === want) {
109
+ el.setAttribute("open", open ? "false" : "true");
110
+ setTimeout(() => el.setAttribute("open", want), 0);
111
+ } else {
112
+ el.setAttribute("open", want);
113
+ }
114
+ } else if (typeof window !== "undefined" && typeof window.Wexio === "function") {
115
+ window.Wexio(open ? "open" : "close");
116
+ }
117
+ }
71
118
  }
72
119
 
73
120
  // Safety-net `name` field so ember-cli's package-info-cache, which
package/dist/index.d.ts CHANGED
@@ -43,4 +43,13 @@ export declare class WexioWidgetService {
43
43
  show(): void;
44
44
  hide(): void;
45
45
  shutdown(): void;
46
+ /** Open the panel. */
47
+ open(): void;
48
+ /** Close the panel. */
49
+ close(): void;
50
+ /** Navigate to a tab (and optionally a help article / news post); opens the panel. */
51
+ navigate(target: {
52
+ tab: "home" | "messages" | "help" | "news" | "profile";
53
+ article?: { kind: "help"; slug: string } | { kind: "news"; id: string };
54
+ }): void;
46
55
  }
package/dist/index.js CHANGED
@@ -42,6 +42,9 @@ function ensureRuntime() {
42
42
  document.head.appendChild(script);
43
43
  }
44
44
 
45
+ /** Monotonic nonce so every `navigate()` is a new request. */
46
+ let navNonce = 0;
47
+
45
48
  export class WexioWidgetService {
46
49
  constructor() {
47
50
  ensureRuntime();
@@ -78,4 +81,48 @@ export class WexioWidgetService {
78
81
  if (typeof window === "undefined") return;
79
82
  if (typeof window.Wexio === "function") window.Wexio("shutdown");
80
83
  }
84
+
85
+ /** Open the panel (the widget element's controlled `open`, else the loader command). */
86
+ open() {
87
+ this._setOpen(true);
88
+ }
89
+
90
+ /** Close the panel. */
91
+ close() {
92
+ this._setOpen(false);
93
+ }
94
+
95
+ /**
96
+ * Navigate to a tab (and optionally a help article / news post) without a remount; opens the
97
+ * panel. `{ tab, article? }`; every call is a new request.
98
+ */
99
+ navigate(target) {
100
+ const el = this.element;
101
+ if (el) {
102
+ navNonce += 1;
103
+ el.previewTab = { ...target, nonce: navNonce };
104
+ } else if (typeof window !== "undefined" && typeof window.Wexio === "function") {
105
+ window.Wexio("navigate", target);
106
+ }
107
+ }
108
+
109
+ _setOpen(open) {
110
+ const el = this.element;
111
+ if (el) {
112
+ const want = open ? "true" : "false";
113
+ // Idempotent: already in the wanted state (read from the rendered panel) -> nothing to do.
114
+ const panel = el.shadowRoot && el.shadowRoot.querySelector("[data-wx-panel]");
115
+ if (panel && !panel.hasAttribute("inert") === open) return;
116
+ // The widget reacts to the attribute CHANGING. It already says `want` but the panel is not
117
+ // there (the visitor toggled it since): flip it away first so this call is a transition again.
118
+ if (el.getAttribute("open") === want) {
119
+ el.setAttribute("open", open ? "false" : "true");
120
+ setTimeout(() => el.setAttribute("open", want), 0);
121
+ } else {
122
+ el.setAttribute("open", want);
123
+ }
124
+ } else if (typeof window !== "undefined" && typeof window.Wexio === "function") {
125
+ window.Wexio(open ? "open" : "close");
126
+ }
127
+ }
81
128
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wexio/messenger-widget-ember",
3
- "version": "1.5.3",
3
+ "version": "1.6.0",
4
4
  "description": "Ember integration for the Wexio web messenger. Service helper around the <wexio-widget> custom element.",
5
5
  "license": "MIT",
6
6
  "private": false,