@sawport/react-sdk 1.2.5-alpha.2 → 1.2.5-alpha.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.
- package/README.md +121 -57
- package/dist/index.js +1264 -23532
- package/dist/index.standalone.js +42 -0
- package/dist/index.umd.js +8 -61
- package/dist/react-sdk.css +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,62 +1,120 @@
|
|
|
1
1
|
# Getting Started With Sawport Widget
|
|
2
2
|
|
|
3
|
-
## Web Usage
|
|
4
|
-
|
|
3
|
+
## Web Usage (CDN)
|
|
4
|
+
|
|
5
|
+
### Step 1: Add Required Scripts and Styles to HTML Head
|
|
6
|
+
Add the React importmap and Sawport widget CSS to your HTML `<head>` tag:
|
|
7
|
+
|
|
5
8
|
```html
|
|
6
9
|
<html>
|
|
7
10
|
<head>
|
|
8
|
-
<
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
<script type="importmap">
|
|
12
|
+
{
|
|
13
|
+
"imports": {
|
|
14
|
+
"react": "https://esm.sh/react@19.1.1",
|
|
15
|
+
"react-dom": "https://esm.sh/react-dom@19.1.1"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
</script>
|
|
19
|
+
<link
|
|
20
|
+
href="https://esm.sh/@sawport/react-sdk/dist/react-sdk.css"
|
|
21
|
+
rel="stylesheet"
|
|
22
|
+
/>
|
|
23
|
+
</head>
|
|
17
24
|
```
|
|
18
25
|
|
|
19
|
-
###
|
|
20
|
-
|
|
21
|
-
Global variable `sawportSDK` will be exposed to your webpage which you can access its method and properties.
|
|
26
|
+
### Step 2: Create Widget Container and Mount Script
|
|
27
|
+
Add the widget container and mounting script after the `<body>` tag:
|
|
22
28
|
|
|
23
|
-
**Important**: Use the `standalone` bundle for CDN usage to prevent React version conflicts:
|
|
24
29
|
```html
|
|
25
|
-
|
|
26
|
-
<
|
|
27
|
-
</body>
|
|
28
|
-
```
|
|
30
|
+
<body>
|
|
31
|
+
<div style="position: fixed; bottom: 20px; right: 20px; z-index: 200" id="sawport-widget"></div>
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
<script type="module">
|
|
34
|
+
import {
|
|
35
|
+
mountWidget,
|
|
36
|
+
setSawportConfig,
|
|
37
|
+
} from "https://esm.sh/@sawport/react-sdk";
|
|
38
|
+
|
|
39
|
+
function docReady(fn) {
|
|
35
40
|
['complete', 'interactive'].includes(document.readyState)
|
|
36
41
|
? setTimeout(fn, 1)
|
|
37
42
|
: document.addEventListener('DOMContentLoaded', fn);
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
docReady(() =>
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
docReady(() => mountWidget(
|
|
46
|
+
{
|
|
47
|
+
baseURL: "https://{{BASE_URL}}",
|
|
48
|
+
apiURL: "https://{{BASE_URL}}/api/v1/",
|
|
49
|
+
projectId: "{{PROJECT_ID}}",
|
|
50
|
+
user: {email: 'example@email.com', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}, // optional
|
|
51
|
+
},
|
|
52
|
+
"sawport-widget"
|
|
53
|
+
))
|
|
46
54
|
</script>
|
|
47
55
|
</body>
|
|
48
56
|
```
|
|
49
57
|
|
|
58
|
+
### Complete Example
|
|
59
|
+
```html
|
|
60
|
+
<!DOCTYPE html>
|
|
61
|
+
<html>
|
|
62
|
+
<head>
|
|
63
|
+
<script type="importmap">
|
|
64
|
+
{
|
|
65
|
+
"imports": {
|
|
66
|
+
"react": "https://esm.sh/react@19.1.1",
|
|
67
|
+
"react-dom": "https://esm.sh/react-dom@19.1.1"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
</script>
|
|
71
|
+
<link
|
|
72
|
+
href="https://esm.sh/@sawport/react-sdk/dist/react-sdk.css"
|
|
73
|
+
rel="stylesheet"
|
|
74
|
+
/>
|
|
75
|
+
</head>
|
|
76
|
+
<body>
|
|
77
|
+
<!-- Your page content -->
|
|
78
|
+
|
|
79
|
+
<div style="position: fixed; bottom: 20px; right: 20px; z-index: 200" id="sawport-widget"></div>
|
|
80
|
+
|
|
81
|
+
<script type="module">
|
|
82
|
+
import {
|
|
83
|
+
mountWidget,
|
|
84
|
+
setSawportConfig,
|
|
85
|
+
} from "https://esm.sh/@sawport/react-sdk";
|
|
86
|
+
|
|
87
|
+
function docReady(fn) {
|
|
88
|
+
['complete', 'interactive'].includes(document.readyState)
|
|
89
|
+
? setTimeout(fn, 1)
|
|
90
|
+
: document.addEventListener('DOMContentLoaded', fn);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
docReady(() => mountWidget(
|
|
94
|
+
{
|
|
95
|
+
baseURL: "https://your-dashboard-domain.com",
|
|
96
|
+
apiURL: "https://your-dashboard-domain.com/api/v1/",
|
|
97
|
+
projectId: "your-project-id",
|
|
98
|
+
user: {email: 'example@email.com', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}, // optional
|
|
99
|
+
},
|
|
100
|
+
"sawport-widget"
|
|
101
|
+
))
|
|
102
|
+
</script>
|
|
103
|
+
</body>
|
|
104
|
+
</html>
|
|
105
|
+
```
|
|
106
|
+
|
|
50
107
|
### Setting up enterprise credentials
|
|
51
|
-
|
|
108
|
+
You can dynamically update the Sawport configuration using `setSawportConfig`:
|
|
52
109
|
```js
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
110
|
+
import { setSawportConfig } from "https://esm.sh/@sawport/react-sdk";
|
|
111
|
+
|
|
112
|
+
setSawportConfig({
|
|
113
|
+
baseURL: 'https://{DASHBOARD_HOST_DOMAIN}',
|
|
114
|
+
apiURL: 'https://{DASHBOARD_HOST_DOMAIN}/api/v1/',
|
|
115
|
+
projectId: 'XXXXXXXXXXXXXX',
|
|
116
|
+
user: {email: 'example@email.com', mobile: '080XXXXXXXXX', name: 'Firstname Lastname'}
|
|
117
|
+
})
|
|
60
118
|
```
|
|
61
119
|
|
|
62
120
|
# Usage In REACTJS
|
|
@@ -110,39 +168,45 @@ setSawportConfig({
|
|
|
110
168
|
<link rel="icon" href="/favicon.ico">
|
|
111
169
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
112
170
|
<title>Vite App</title>
|
|
113
|
-
<!-- ADD
|
|
114
|
-
<
|
|
171
|
+
<!-- ADD REACT IMPORTMAP -->
|
|
172
|
+
<script type="importmap">
|
|
173
|
+
{
|
|
174
|
+
"imports": {
|
|
175
|
+
"react": "https://esm.sh/react@19.1.1",
|
|
176
|
+
"react-dom": "https://esm.sh/react-dom@19.1.1"
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
</script>
|
|
180
|
+
<!-- ADD SAWPORT SDK CSS -->
|
|
181
|
+
<link href="https://esm.sh/@sawport/react-sdk/dist/react-sdk.css" rel="stylesheet" />
|
|
115
182
|
</head>
|
|
116
183
|
<body>
|
|
117
184
|
<div id="app"></div>
|
|
118
|
-
<!-- CREATE A DIV TO HOLD SAWPORT WIDGET
|
|
185
|
+
<!-- CREATE A DIV TO HOLD SAWPORT WIDGET -->
|
|
119
186
|
<div id="sawport-widget"></div>
|
|
120
|
-
<!-- ADD SAWPORT SDK JS -->
|
|
121
|
-
<script type="module" src="https://unpkg.com/@sawport/react-sdk@latest/dist/index.js"></script>
|
|
122
187
|
<script type="module" src="/src/main.js"></script>
|
|
123
188
|
</body>
|
|
124
189
|
</html>
|
|
125
190
|
```
|
|
126
191
|
|
|
127
|
-
## Mounting Sawport SDK From Your
|
|
128
|
-
You need to mount the widget from your
|
|
129
|
-
By pulling the Sawport SDK, `sawportSDK` variable would be exposed to your vuejs app globally.
|
|
192
|
+
## Mounting Sawport SDK From Your Vue.js APP
|
|
193
|
+
You need to mount the widget from your Vue.js app. Import the SDK functions directly using ES modules.
|
|
130
194
|
```vue
|
|
131
195
|
<script setup>
|
|
196
|
+
import { onMounted } from 'vue'
|
|
197
|
+
import { mountWidget } from 'https://esm.sh/@sawport/react-sdk'
|
|
132
198
|
import HelloWorld from './components/HelloWorld.vue'
|
|
133
199
|
|
|
134
|
-
|
|
200
|
+
const dashboardUrl = 'https://{DASHBOARD_HOST_DOMAIN}'
|
|
135
201
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
user: {email: 'example@email.com', mobile: '2348123456789', name: 'Firstname Lastname'}, // optional
|
|
145
|
-
}, 'sawport-widget')
|
|
202
|
+
onMounted(() => {
|
|
203
|
+
mountWidget({
|
|
204
|
+
baseURL: dashboardUrl,
|
|
205
|
+
apiURL: `${dashboardUrl}/api/v1/`,
|
|
206
|
+
projectId: 'XXXXXXXXXXXXXX',
|
|
207
|
+
user: {email: 'example@email.com', mobile: '2348123456789', name: 'Firstname Lastname'}, // optional
|
|
208
|
+
}, 'sawport-widget')
|
|
209
|
+
})
|
|
146
210
|
</script>
|
|
147
211
|
|
|
148
212
|
<template>
|