@yartsun/hypershadow-widget 0.1.4 → 0.1.5
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 +89 -2
- package/package.json +1 -1
- package/types/standalone.d.ts +17 -4
package/README.md
CHANGED
|
@@ -12,11 +12,98 @@ Chat widget for Hypershadow platform with WebSocket communication.
|
|
|
12
12
|
# Install dependencies
|
|
13
13
|
npm i
|
|
14
14
|
|
|
15
|
-
# Build the
|
|
15
|
+
# Build the main demo app (for local development)
|
|
16
16
|
npm run build
|
|
17
|
+
|
|
18
|
+
# Build library bundle (used as npm package entry)
|
|
19
|
+
npm run build:lib
|
|
20
|
+
|
|
21
|
+
# Build standalone bundle (for script tag / external embedding)
|
|
22
|
+
npm run build:vanilla
|
|
23
|
+
|
|
24
|
+
# Build everything
|
|
25
|
+
npm run build:all
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
Build output will be located in the `/dist` directory:
|
|
29
|
+
|
|
30
|
+
- `dist/lib` – library build used by `@yartsun/hypershadow-widget`
|
|
31
|
+
- `dist/standalone` – standalone build (IIFE + ES module)
|
|
32
|
+
|
|
33
|
+
## Library usage (ESM / TypeScript)
|
|
34
|
+
|
|
35
|
+
Install the package:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm i @yartsun/hypershadow-widget
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Use the library entry (components/helpers from `dist/lib`), for example:
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
import { /* your exports */ } from '@yartsun/hypershadow-widget';
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Standalone entry (ESM)
|
|
48
|
+
|
|
49
|
+
For embedding the widget into any host app (Nuxt, React, vanilla, etc.) you can use the
|
|
50
|
+
standalone entry that is now exported via package `exports`:
|
|
51
|
+
|
|
52
|
+
```ts
|
|
53
|
+
import { mount } from '@yartsun/hypershadow-widget/standalone';
|
|
54
|
+
|
|
55
|
+
mount({
|
|
56
|
+
target: '#chat-widget',
|
|
57
|
+
props: {
|
|
58
|
+
isEmbedded: true,
|
|
59
|
+
isPreview: true,
|
|
60
|
+
// link: 'wss://your-websocket-server.com/chat',
|
|
61
|
+
// configWidget: { ... }
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
This entry is backed by:
|
|
67
|
+
|
|
68
|
+
- JS: `dist/standalone/hs-widget.es.js`
|
|
69
|
+
- Types: `types/standalone.d.ts`
|
|
70
|
+
|
|
71
|
+
### ESM usage examples
|
|
72
|
+
|
|
73
|
+
**Nuxt / Vue (client-only mount)**:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
// Any client-only hook (e.g. onMounted in a component)
|
|
77
|
+
import { mount } from '@yartsun/hypershadow-widget/standalone';
|
|
78
|
+
|
|
79
|
+
onMounted(() => {
|
|
80
|
+
mount({
|
|
81
|
+
target: '#chat-widget',
|
|
82
|
+
props: {
|
|
83
|
+
isEmbedded: true,
|
|
84
|
+
isPreview: true,
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Plain ESM/TypeScript app**:
|
|
91
|
+
|
|
92
|
+
```ts
|
|
93
|
+
import { mount } from '@yartsun/hypershadow-widget/standalone';
|
|
94
|
+
|
|
95
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
96
|
+
mount({
|
|
97
|
+
target: '#chat-widget',
|
|
98
|
+
props: {
|
|
99
|
+
link: 'wss://your-websocket-server.com/chat',
|
|
100
|
+
},
|
|
101
|
+
});
|
|
102
|
+
});
|
|
17
103
|
```
|
|
18
104
|
|
|
19
|
-
|
|
105
|
+
For `<script>`/IIFE-based usage and more advanced configuration examples,
|
|
106
|
+
see `STANDALONE.md`.
|
|
20
107
|
|
|
21
108
|
## Module Federation Usage
|
|
22
109
|
|
package/package.json
CHANGED
package/types/standalone.d.ts
CHANGED
|
@@ -2,15 +2,28 @@
|
|
|
2
2
|
// This file is shipped with the npm package and is used for ESM/TS imports like:
|
|
3
3
|
// import { mount } from '@yartsun/hypershadow-widget/standalone';
|
|
4
4
|
|
|
5
|
-
import type { App } from 'vue';
|
|
6
|
-
|
|
7
5
|
export type StandaloneMountOptions = {
|
|
8
6
|
target: string | HTMLElement;
|
|
9
7
|
props?: Record<string, any>;
|
|
10
8
|
};
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
export interface StandaloneWidgetApi {
|
|
11
|
+
id: string | any;
|
|
12
|
+
setScenario: (type: string, options?: any) => Promise<void>;
|
|
13
|
+
clearScenario: () => Promise<void>;
|
|
14
|
+
setOpen: (open: boolean) => void;
|
|
15
|
+
setActive: (active: boolean) => void;
|
|
16
|
+
setInputDisabled: (disabled: boolean) => void;
|
|
17
|
+
setShowReconnectNotice: (show: boolean) => void;
|
|
18
|
+
setMessages: (list: any[]) => void;
|
|
19
|
+
pushMessage: (msg: any) => void;
|
|
20
|
+
setSnippet: (data: any | null) => void;
|
|
21
|
+
resetToLive: () => Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Mounts the chat widget into the given DOM target and returns the same control API
|
|
25
|
+
// object that is registered in window.hswWidgets[widgetId].
|
|
26
|
+
export declare function mount(options: StandaloneMountOptions): StandaloneWidgetApi;
|
|
14
27
|
|
|
15
28
|
declare const _default: {
|
|
16
29
|
mount: typeof mount;
|