@namphuongtechnologi/np-hub 0.1.8 → 0.1.10
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 +174 -79
- package/dist/{chunk-ZZQ7CSFN.js → chunk-LH3GOL37.js} +64 -26
- package/dist/chunk-LH3GOL37.js.map +1 -0
- package/dist/index.cjs +63 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/np-hub.min.global.js +31 -51
- package/dist/react.cjs +72 -26
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +10 -2
- package/dist/react.d.ts +10 -2
- package/dist/react.js +10 -2
- package/dist/react.js.map +1 -1
- package/dist/register.cjs +63 -25
- package/dist/register.cjs.map +1 -1
- package/dist/register.js +1 -1
- package/dist/{support-widget.element-n5LtBGX6.d.cts → support-widget.element-DjptQgh_.d.cts} +9 -7
- package/dist/{support-widget.element-n5LtBGX6.d.ts → support-widget.element-DjptQgh_.d.ts} +9 -7
- package/docs/DEVELOPER_GUIDE.md +137 -57
- package/docs/PUBLIC_RELEASE.md +63 -45
- package/docs/USAGE_STATIC_REACT.md +152 -9
- package/package.json +1 -1
- package/dist/chunk-ZZQ7CSFN.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,50 +1,67 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @namphuongtechnologi/np-hub
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Floating support widget for Nam Phương So applications. Drop it into any static site or React app — users open a form, submit a support request, and the request is sent to the Nam Phương API.
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@namphuongtechnologi/np-hub)
|
|
6
|
+
[](./LICENSE)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Features
|
|
11
|
+
|
|
12
|
+
- **Web Component** (`<np-hub>`) — works in plain HTML and most frameworks
|
|
13
|
+
- **React wrapper** — typed `SupportWidget` component
|
|
14
|
+
- **Drag-and-drop launcher** — position persists in `localStorage`
|
|
15
|
+
- **Form prefill** — optional user / content / attachment seeding; required fields still validated on submit
|
|
16
|
+
- **Environment switch** — Production by default; Development via `isDev` / `is-dev`
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @namphuongtechnologi/np-hub
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**CDN (static HTML, no npm):**
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
https://cdn.jsdelivr.net/npm/@namphuongtechnologi/np-hub@0.1.9/dist/np-hub.min.global.js
|
|
30
|
+
```
|
|
4
31
|
|
|
5
32
|
---
|
|
6
33
|
|
|
7
|
-
##
|
|
34
|
+
## Quick start
|
|
8
35
|
|
|
9
|
-
|
|
36
|
+
### Static HTML
|
|
10
37
|
|
|
11
|
-
|
|
38
|
+
Create a config script, then include it once in your page.
|
|
39
|
+
|
|
40
|
+
**`np-hub.js`**
|
|
12
41
|
|
|
13
42
|
```js
|
|
14
43
|
var NP_HUB_CDN =
|
|
15
|
-
"https://cdn.jsdelivr.net/npm/@namphuongtechnologi/np-hub@0.1.
|
|
44
|
+
"https://cdn.jsdelivr.net/npm/@namphuongtechnologi/np-hub@0.1.9/dist/np-hub.min.global.js";
|
|
16
45
|
|
|
17
46
|
function initNpHub() {
|
|
18
47
|
var widget = document.createElement("np-hub");
|
|
19
|
-
widget.setAttribute("project-id", "NPP"); // bắt buộc
|
|
20
|
-
// widget.setAttribute("is-dev", ""); // bỏ comment nếu dùng API dev
|
|
21
48
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
49
|
+
widget.setConfig({
|
|
50
|
+
projectId: "NPP",
|
|
51
|
+
isDev: false,
|
|
52
|
+
priority: 0,
|
|
53
|
+
coordinators: [],
|
|
54
|
+
emailContacts: [],
|
|
55
|
+
});
|
|
26
56
|
|
|
27
57
|
document.body.appendChild(widget);
|
|
28
58
|
|
|
29
|
-
// Optional khi config — chỉ prefill; form UI vẫn bắt buộc nhập
|
|
30
|
-
// widget.setUser({
|
|
31
|
-
// name: "Nguyen Van A",
|
|
32
|
-
// email: "a@gmail.com",
|
|
33
|
-
// phoneNumber: "0912345678",
|
|
34
|
-
// });
|
|
35
|
-
|
|
36
|
-
// Optional khi config — chỉ prefill nội dung/file
|
|
37
|
-
// widget.setFormPrefill({
|
|
38
|
-
// content: "Mô tả sự cố cần hỗ trợ...",
|
|
39
|
-
// attachments: [],
|
|
40
|
-
// });
|
|
41
|
-
|
|
42
59
|
widget.addEventListener("np-hub-submit-success", function (event) {
|
|
43
|
-
console.log("
|
|
60
|
+
console.log("Support request created:", event.detail);
|
|
44
61
|
});
|
|
45
62
|
|
|
46
63
|
widget.addEventListener("np-hub-submit-error", function (event) {
|
|
47
|
-
console.error("
|
|
64
|
+
console.error("Support request failed:", event.detail);
|
|
48
65
|
});
|
|
49
66
|
}
|
|
50
67
|
|
|
@@ -54,7 +71,7 @@ script.onload = initNpHub;
|
|
|
54
71
|
document.head.appendChild(script);
|
|
55
72
|
```
|
|
56
73
|
|
|
57
|
-
**`index.html`**
|
|
74
|
+
**`index.html`**
|
|
58
75
|
|
|
59
76
|
```html
|
|
60
77
|
<!doctype html>
|
|
@@ -70,17 +87,11 @@ document.head.appendChild(script);
|
|
|
70
87
|
</html>
|
|
71
88
|
```
|
|
72
89
|
|
|
73
|
-
|
|
90
|
+
Full example: [`examples/static-html/`](./examples/static-html/).
|
|
74
91
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
## B) React
|
|
78
|
-
|
|
79
|
-
```bash
|
|
80
|
-
npm install @namphuongtechnologi/np-hub
|
|
81
|
-
```
|
|
92
|
+
### React
|
|
82
93
|
|
|
83
|
-
|
|
94
|
+
Mount **once** at the application root (`App.tsx`, `main.tsx`, or root layout).
|
|
84
95
|
|
|
85
96
|
```tsx
|
|
86
97
|
import { SupportWidget } from "@namphuongtechnologi/np-hub/react";
|
|
@@ -88,65 +99,149 @@ import { SupportWidget } from "@namphuongtechnologi/np-hub/react";
|
|
|
88
99
|
export default function App() {
|
|
89
100
|
return (
|
|
90
101
|
<>
|
|
91
|
-
{/*
|
|
102
|
+
{/* app content */}
|
|
92
103
|
<SupportWidget
|
|
93
104
|
projectId="NPP"
|
|
94
|
-
isDev
|
|
105
|
+
isDev={false}
|
|
95
106
|
priority={0}
|
|
96
107
|
coordinators={[]}
|
|
97
108
|
emailContacts={[]}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// name: "Nguyen Van A",
|
|
101
|
-
// email: "a@gmail.com",
|
|
102
|
-
// phoneNumber: "0912345678",
|
|
103
|
-
// }}
|
|
104
|
-
// formPrefill={{
|
|
105
|
-
// content: "Mô tả sự cố cần hỗ trợ...",
|
|
106
|
-
// attachments: [],
|
|
107
|
-
// }}
|
|
108
|
-
onSubmitSuccess={(detail) => console.log("Thành công:", detail)}
|
|
109
|
-
onSubmitError={(error) => console.error("Lỗi:", error)}
|
|
109
|
+
onSubmitSuccess={(detail) => console.log("Success:", detail)}
|
|
110
|
+
onSubmitError={(error) => console.error("Error:", error)}
|
|
110
111
|
/>
|
|
111
112
|
</>
|
|
112
113
|
);
|
|
113
114
|
}
|
|
114
115
|
```
|
|
115
116
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
|
123
|
-
|
|
|
124
|
-
| `
|
|
125
|
-
| `
|
|
126
|
-
| `
|
|
127
|
-
| `
|
|
128
|
-
| `
|
|
129
|
-
|
|
130
|
-
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## Configuration
|
|
120
|
+
|
|
121
|
+
### `setConfig` / React props
|
|
122
|
+
|
|
123
|
+
| Name | Required | Default | Description |
|
|
124
|
+
| --------------- | -------- | ------------- | ------------------------------------------------ |
|
|
125
|
+
| `projectId` | No | — | Project code forwarded to the API |
|
|
126
|
+
| `isDev` | No | `false` | `true` → Development API; otherwise Production |
|
|
127
|
+
| `priority` | No | `0` | Request priority |
|
|
128
|
+
| `coordinators` | No | `[]` | Coordinator email list |
|
|
129
|
+
| `emailContacts` | No | `[]` | Contact emails that receive the notification |
|
|
130
|
+
|
|
131
|
+
### Prefill (optional)
|
|
132
|
+
|
|
133
|
+
| Name | Method / prop | Description |
|
|
134
|
+
| ------------- | ----------------- | --------------------------------------------------------------------------- |
|
|
135
|
+
| User | `setUser` / `user` | Prefills name, email, phone. Form UI still requires these fields on submit. |
|
|
136
|
+
| Form content | `setFormPrefill` / `formPrefill` | Prefills `content` and `attachments`. |
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
// Web Component
|
|
140
|
+
widget.setUser({
|
|
141
|
+
name: "Nguyen Van A",
|
|
142
|
+
email: "a@example.com",
|
|
143
|
+
phoneNumber: "0912345678",
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
widget.setFormPrefill({
|
|
147
|
+
content: "Describe the issue...",
|
|
148
|
+
attachments: [],
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
```tsx
|
|
153
|
+
// React
|
|
154
|
+
<SupportWidget
|
|
155
|
+
projectId="NPP"
|
|
156
|
+
user={{
|
|
157
|
+
name: "Nguyen Van A",
|
|
158
|
+
email: "a@example.com",
|
|
159
|
+
phoneNumber: "0912345678",
|
|
160
|
+
}}
|
|
161
|
+
formPrefill={{
|
|
162
|
+
content: "Describe the issue...",
|
|
163
|
+
attachments: [],
|
|
164
|
+
}}
|
|
165
|
+
/>
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Launcher size & position
|
|
169
|
+
|
|
170
|
+
Default: **65×65px**, anchored **20px** from the bottom-right corner.
|
|
171
|
+
|
|
172
|
+
| Attribute / prop | Description |
|
|
173
|
+
| ---------------------- | ------------------------------------------------ |
|
|
174
|
+
| `width` / `height` | Launcher size (default `65`) |
|
|
175
|
+
| `right` / `bottom` | Offset from bottom-right (default `20`) |
|
|
176
|
+
| `left` / `top` | Use instead of `right` / `bottom` for other corners |
|
|
177
|
+
|
|
178
|
+
Numeric values from React props are treated as pixels. After the user drags the launcher, the stored `localStorage` position takes precedence.
|
|
179
|
+
|
|
180
|
+
```js
|
|
181
|
+
widget.setAttribute("right", "24");
|
|
182
|
+
widget.setAttribute("bottom", "24");
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
```tsx
|
|
186
|
+
<SupportWidget projectId="NPP" right={24} bottom={24} />
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Events & methods
|
|
192
|
+
|
|
193
|
+
### Events (Web Component)
|
|
194
|
+
|
|
195
|
+
| Event | When |
|
|
196
|
+
| ----------------------- | --------------------------------- |
|
|
197
|
+
| `np-hub-open` | Modal opens |
|
|
198
|
+
| `np-hub-close` | Modal closes |
|
|
199
|
+
| `np-hub-submit-success` | API accepted the support request |
|
|
200
|
+
| `np-hub-submit-error` | Validation or API failure |
|
|
201
|
+
|
|
202
|
+
React equivalent props: `onOpen`, `onClose`, `onSubmitSuccess`, `onSubmitError`.
|
|
203
|
+
|
|
204
|
+
### Methods (Web Component)
|
|
205
|
+
|
|
206
|
+
| Method | Description |
|
|
207
|
+
| ---------------------- | ------------------------------ |
|
|
208
|
+
| `setConfig(config)` | Apply project / API settings |
|
|
209
|
+
| `setUser(user)` | Prefill requester fields |
|
|
210
|
+
| `setFormPrefill(data)` | Prefill content / attachments |
|
|
211
|
+
| `open()` / `close()` | Open or close the modal |
|
|
131
212
|
|
|
132
213
|
---
|
|
133
214
|
|
|
134
|
-
##
|
|
215
|
+
## API environments
|
|
135
216
|
|
|
136
|
-
|
|
|
137
|
-
|
|
|
138
|
-
| Production (
|
|
139
|
-
| Development (`
|
|
217
|
+
| Environment | Base URL |
|
|
218
|
+
| ----------------------------------- | ------------------------------------------------- |
|
|
219
|
+
| Production (default) | `https://namphuong-api.azurewebsites.net` |
|
|
220
|
+
| Development (`isDev` / `is-dev`) | `https://namphuong-api-dev.azurewebsites.net` |
|
|
140
221
|
|
|
141
|
-
|
|
222
|
+
---
|
|
223
|
+
|
|
224
|
+
## Troubleshooting
|
|
225
|
+
|
|
226
|
+
| Error | Resolution |
|
|
227
|
+
| ---------------------------------------------- | -------------------------------------------------------------------------- |
|
|
228
|
+
| `projectId cannot be empty.` | If provided, `projectId` / `project-id` must be a non-empty string |
|
|
229
|
+
| `user.name/email/phoneNumber is required.` | Requester fields are required on submit; `user` only prefills |
|
|
230
|
+
| `Content is required.` | User must enter message content before submit |
|
|
231
|
+
| API call fails in local testing | Set `isDev` / `is-dev` when targeting the Development environment |
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
## Documentation
|
|
142
236
|
|
|
143
|
-
|
|
|
144
|
-
|
|
|
145
|
-
|
|
|
146
|
-
|
|
|
147
|
-
|
|
|
148
|
-
|
|
237
|
+
| Document | Audience |
|
|
238
|
+
| -------- | -------- |
|
|
239
|
+
| [Usage (static & React)](./docs/USAGE_STATIC_REACT.md) | Integrators |
|
|
240
|
+
| [Developer guide](./docs/DEVELOPER_GUIDE.md) | Contributors |
|
|
241
|
+
| [Public release](./docs/PUBLIC_RELEASE.md) | Maintainers |
|
|
242
|
+
|
|
243
|
+
---
|
|
149
244
|
|
|
150
245
|
## License
|
|
151
246
|
|
|
152
|
-
MIT
|
|
247
|
+
MIT © Nam Phương So
|