@superleapai/flow-ui 2.5.17 → 2.5.18

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/core/crm.js CHANGED
@@ -47,10 +47,7 @@
47
47
  if (_bridge) return _bridge;
48
48
 
49
49
  // Via the clean-globals component map
50
- if (
51
- global.FlowUI &&
52
- typeof global.FlowUI._getComponent === "function"
53
- ) {
50
+ if (global.FlowUI && typeof global.FlowUI._getComponent === "function") {
54
51
  var b = global.FlowUI._getComponent("SuperleapBridge");
55
52
  if (b) {
56
53
  _bridge = b;
@@ -71,10 +68,7 @@
71
68
  * Resolve a reference to the superleapClient (SDK wrapper).
72
69
  */
73
70
  function getSuperLeapClient() {
74
- if (
75
- global.FlowUI &&
76
- typeof global.FlowUI._getComponent === "function"
77
- ) {
71
+ if (global.FlowUI && typeof global.FlowUI._getComponent === "function") {
78
72
  var c = global.FlowUI._getComponent("superleapClient");
79
73
  if (c) return c;
80
74
  }
@@ -117,9 +111,7 @@
117
111
  var bridge = getBridge();
118
112
 
119
113
  if (!bridge) {
120
- return Promise.reject(
121
- new Error("SuperleapCRM: bridge.js is not loaded"),
122
- );
114
+ return Promise.reject(new Error("SuperleapCRM: bridge.js is not loaded"));
123
115
  }
124
116
 
125
117
  _connectPromise = bridge
@@ -159,7 +151,10 @@
159
151
 
160
152
  // Dispatch a DOM event so code without a reference to the promise
161
153
  // can react (mirrors the existing 'superleap-flow:ready' pattern)
162
- if (typeof CustomEvent !== "undefined" && typeof document !== "undefined") {
154
+ if (
155
+ typeof CustomEvent !== "undefined" &&
156
+ typeof document !== "undefined"
157
+ ) {
163
158
  var evt = new CustomEvent("superleap-crm:connected", {
164
159
  detail: { context: _context, config: _config },
165
160
  });
@@ -252,6 +247,21 @@
252
247
  }
253
248
  }
254
249
 
250
+ /**
251
+ * Register a callback for when the CRM form is submitted successfully.
252
+ * The CRM sends a 'crm:formSubmitSuccess' message after the form saves.
253
+ *
254
+ * @param {Function} callback – receives (payload)
255
+ * @returns {Function} unsubscribe function
256
+ */
257
+ function onFormSubmitSuccess(callback) {
258
+ var bridge = getBridge();
259
+ if (!bridge) {
260
+ return function () {};
261
+ }
262
+ return bridge.onMessage("crm:onFormSubmitSuccess", callback);
263
+ }
264
+
255
265
  // ---------------------------------------------------------------------------
256
266
  // Context
257
267
  // ---------------------------------------------------------------------------
@@ -326,6 +336,7 @@
326
336
  global.superleapClient.disconnect = disconnect;
327
337
  global.superleapClient.setLoading = setLoading;
328
338
  global.superleapClient.closeForm = closeForm;
339
+ global.superleapClient.onFormSubmitSuccess = onFormSubmitSuccess;
329
340
  global.superleapClient.toast = toast;
330
341
  global.superleapClient.navigate = navigate;
331
342
  global.superleapClient.getContext = getContext;