@superleapai/flow-ui 1.0.1 → 2.1.1

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/README.md CHANGED
@@ -18,13 +18,13 @@ npm install @superleapai/flow-ui
18
18
  <!DOCTYPE html>
19
19
  <html>
20
20
  <head>
21
- <link rel="stylesheet" href="node_modules/@superleapai/flow-ui/dist/output.css">
21
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@superleapai/flow-ui@latest/dist/output.css">
22
22
  </head>
23
23
  <body>
24
24
  <div id="app"></div>
25
25
 
26
26
  <!-- Single script tag - includes SuperLeap SDK and all components -->
27
- <script src="node_modules/@superleapai/flow-ui/index.js"></script>
27
+ <script src="https://cdn.jsdelivr.net/npm/@superleapai/flow-ui@latest/index.js"></script>
28
28
 
29
29
  <script>
30
30
  // Wait for library to be ready
@@ -75,34 +75,179 @@ npm install @superleapai/flow-ui
75
75
  </html>
76
76
  ```
77
77
 
78
- ### ES Module Usage
78
+ ## 🔌 CRM Embedded Usage (Inside iframes)
79
79
 
80
- ```javascript
81
- import { FlowUI, SuperLeap } from '@superleapai/flow-ui';
80
+ When your flow is embedded in the SuperLeap CRM as an iframe, use `SuperLeap.connect()` to establish a secure connection. This automatically provides credentials and context without requiring hardcoded API keys.
82
81
 
83
- // Initialize SuperLeap SDK
84
- SuperLeap.init({ apiKey: 'YOUR_KEY' });
82
+ ```html
83
+ <!DOCTYPE html>
84
+ <html>
85
+ <head>
86
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@superleapai/flow-ui@latest/dist/output.css">
87
+ </head>
88
+ <body>
89
+ <div id="app"></div>
85
90
 
86
- // Initialize state
87
- FlowUI.initState({ name: '', email: '' });
91
+ <script src="https://cdn.jsdelivr.net/npm/@superleapai/flow-ui@latest/index.js"></script>
88
92
 
89
- // Create components
90
- const nameInput = FlowUI.createInput({
91
- label: 'Name',
92
- fieldId: 'name',
93
- required: true
93
+ <script>
94
+ document.addEventListener('superleap-flow:ready', async function() {
95
+ try {
96
+ // Connect to CRM - SDK is auto-initialized with credentials
97
+ // flowId must match the custom_id of your iframe component in the CRM
98
+ const { context, config } = await SuperLeap.connect({
99
+ flowId: 'my-onboarding-flow' // Use the custom_id from your iframe component
100
+ });
101
+
102
+ // Access CRM context (orgId, userId, recordId, etc.)
103
+ console.log('Organization:', context.orgId);
104
+ console.log('Current User:', context.userId);
105
+ console.log('Record ID:', context.recordId); // if in record context
106
+
107
+ // Initialize your form state
108
+ FlowUI.initState({
109
+ name: '',
110
+ email: '',
111
+ // Pre-fill with context data if needed
112
+ accountId: context.recordId
113
+ });
114
+
115
+ // Build your UI
116
+ const app = document.getElementById('app');
117
+ const screen = FlowUI.createScreen('Onboarding', 'Complete your profile');
118
+ const grid = FlowUI.createGrid();
119
+
120
+ grid.appendChild(FlowUI.createInput({
121
+ label: 'Name',
122
+ fieldId: 'name',
123
+ required: true
124
+ }));
125
+
126
+ grid.appendChild(FlowUI.createInput({
127
+ label: 'Email',
128
+ fieldId: 'email',
129
+ type: 'email',
130
+ required: true
131
+ }));
132
+
133
+ const submitBtn = FlowUI.createButton({
134
+ variant: 'primary',
135
+ text: 'Submit',
136
+ onClick: async () => {
137
+ const data = FlowUI.getState();
138
+
139
+ // Show loading in CRM
140
+ SuperLeap.setLoading(true);
141
+
142
+ try {
143
+ // Your business logic here
144
+ const sdk = SuperLeap.getSdk();
145
+ await sdk.records.create('contacts', data);
146
+
147
+ // Show success notification in CRM
148
+ SuperLeap.toast('Profile created successfully!', 'success');
149
+
150
+ // Close the form/modal
151
+ SuperLeap.closeForm();
152
+ } catch (error) {
153
+ SuperLeap.toast('Failed to create profile', 'error');
154
+ } finally {
155
+ SuperLeap.setLoading(false);
156
+ }
157
+ }
158
+ });
159
+
160
+ screen.appendChild(grid);
161
+ screen.appendChild(submitBtn);
162
+ app.appendChild(screen);
163
+
164
+ } catch (error) {
165
+ console.error('Failed to connect to CRM:', error);
166
+ }
167
+ });
168
+ </script>
169
+ </body>
170
+ </html>
171
+ ```
172
+
173
+ #### CRM Bridge API
174
+
175
+ **Connect to CRM:**
176
+ ```javascript
177
+ const { context, config } = await SuperLeap.connect({
178
+ flowId: 'my-flow', // Required: the custom_id of your iframe component in CRM
179
+ crmOrigin: 'https://...', // Optional: validate CRM origin
180
+ autoInit: true, // Optional: auto-initialize SDK (default: true)
181
+ timeout: 5000 // Optional: connection timeout in ms (default: 5000)
94
182
  });
95
183
  ```
96
184
 
97
- ### CommonJS Usage
185
+ **Access CRM Context:**
186
+ ```javascript
187
+ const context = SuperLeap.getContext();
188
+ // {
189
+ // orgId: string,
190
+ // userId: string,
191
+ // recordId?: string, // Present if iframe is in a record view
192
+ // objectSlug?: string, // e.g., 'accounts', 'contacts'
193
+ // formId?: string,
194
+ // componentId?: string
195
+ // }
196
+ ```
98
197
 
198
+ **CRM Actions:**
99
199
  ```javascript
100
- const { FlowUI, SuperLeap } = require('@superleapai/flow-ui');
200
+ // Show/hide loading overlay in CRM
201
+ SuperLeap.setLoading(true);
202
+ SuperLeap.setLoading(false);
101
203
 
102
- SuperLeap.init({ apiKey: 'YOUR_KEY' });
103
- FlowUI.initState({ name: '' });
204
+ // Close the current form/modal in CRM
205
+ SuperLeap.closeForm();
206
+
207
+ // Show toast notification in CRM
208
+ SuperLeap.toast('Success!', 'success', 3000);
209
+ SuperLeap.toast('Error occurred', 'error');
210
+ SuperLeap.toast('Warning message', 'warning');
211
+ SuperLeap.toast('Info message', 'info');
212
+
213
+ // Navigate to a path in CRM
214
+ SuperLeap.navigate('/records/contacts/123');
215
+ ```
216
+
217
+ **Custom Events (CRM ↔ Iframe Communication):**
218
+ ```javascript
219
+ // Send custom event to CRM
220
+ SuperLeap.send('form-submitted', { values: {...} });
221
+ SuperLeap.send('validation-failed', { errors: [...] });
222
+
223
+ // Listen for custom events from CRM
224
+ const unsubscribe = SuperLeap.on('prefill-data', (data) => {
225
+ FlowUI.setState(data);
226
+ });
227
+
228
+ // Remove listener
229
+ SuperLeap.off('prefill-data', callbackFunction);
230
+
231
+ // Or use unsubscribe function
232
+ unsubscribe();
233
+ ```
234
+
235
+ **Check Connection Status:**
236
+ ```javascript
237
+ if (SuperLeap.isConnected()) {
238
+ // Connected to CRM
239
+ }
104
240
  ```
105
241
 
242
+ **Disconnect:**
243
+ ```javascript
244
+ SuperLeap.disconnect();
245
+ ```
246
+
247
+ #### React Native WebView Support
248
+
249
+ The bridge automatically detects and supports React Native WebView environments. No configuration changes needed - use the same API as shown above.
250
+
106
251
  ## 🎯 What's Exposed
107
252
 
108
253
  ```javascript