scribe-widget 1.0.3 → 1.0.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/dist/scribe-widget.es.js +56 -48
- package/dist/scribe-widget.umd.js +2 -2
- package/package.json +1 -1
- package/src/components/ConfigState.tsx +11 -2
- package/src/index.tsx +11 -11
package/package.json
CHANGED
|
@@ -7,7 +7,11 @@ interface ConfigStateProps {
|
|
|
7
7
|
initialBaseUrl?: string;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export function ConfigState({
|
|
10
|
+
export function ConfigState({
|
|
11
|
+
onSubmit,
|
|
12
|
+
initialApiKey = '',
|
|
13
|
+
initialBaseUrl = '',
|
|
14
|
+
}: ConfigStateProps) {
|
|
11
15
|
const [apiKey, setApiKey] = useState(initialApiKey);
|
|
12
16
|
const [baseUrl, setBaseUrl] = useState(initialBaseUrl);
|
|
13
17
|
const [error, setError] = useState('');
|
|
@@ -25,7 +29,12 @@ export function ConfigState({ onSubmit, initialApiKey = '', initialBaseUrl = ''
|
|
|
25
29
|
};
|
|
26
30
|
|
|
27
31
|
return (
|
|
28
|
-
<div
|
|
32
|
+
<div
|
|
33
|
+
className="config-state"
|
|
34
|
+
style={{
|
|
35
|
+
zIndex: 9999,
|
|
36
|
+
}}
|
|
37
|
+
>
|
|
29
38
|
<div className="logo">
|
|
30
39
|
<div className="logo-icon">
|
|
31
40
|
<LogoIcon />
|
package/src/index.tsx
CHANGED
|
@@ -44,18 +44,12 @@ class ScribeWidget {
|
|
|
44
44
|
private render(): void {
|
|
45
45
|
if (!this.root || !this.visible) return;
|
|
46
46
|
|
|
47
|
-
this.root.render(
|
|
48
|
-
<App
|
|
49
|
-
config={this.config}
|
|
50
|
-
onClose={() => this.hide()}
|
|
51
|
-
/>
|
|
52
|
-
);
|
|
47
|
+
this.root.render(<App config={this.config} onClose={() => this.hide()} />);
|
|
53
48
|
}
|
|
54
49
|
|
|
55
50
|
public mount(target?: HTMLElement | string): void {
|
|
56
|
-
const targetEl =
|
|
57
|
-
? document.querySelector(target)
|
|
58
|
-
: target || document.body;
|
|
51
|
+
const targetEl =
|
|
52
|
+
typeof target === 'string' ? document.querySelector(target) : target || document.body;
|
|
59
53
|
|
|
60
54
|
if (targetEl) {
|
|
61
55
|
targetEl.appendChild(this.container);
|
|
@@ -94,6 +88,8 @@ function init(config: ScribeWidgetConfig = {} as ScribeWidgetConfig): ScribeWidg
|
|
|
94
88
|
if (widgetInstance) {
|
|
95
89
|
widgetInstance.unmount();
|
|
96
90
|
}
|
|
91
|
+
|
|
92
|
+
console.log(config, 'config - WIDGET');
|
|
97
93
|
widgetInstance = new ScribeWidget(config);
|
|
98
94
|
widgetInstance.mount();
|
|
99
95
|
return widgetInstance;
|
|
@@ -120,11 +116,13 @@ export default EkaScribe;
|
|
|
120
116
|
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
121
117
|
const autoInit = () => {
|
|
122
118
|
// Don't auto-init if already initialized or if data-no-auto-init attribute is present
|
|
123
|
-
const scriptTag =
|
|
119
|
+
const scriptTag =
|
|
120
|
+
document.currentScript || document.querySelector('script[src*="scribe-widget"]');
|
|
124
121
|
if (scriptTag?.hasAttribute('data-no-auto-init')) {
|
|
125
122
|
return;
|
|
126
123
|
}
|
|
127
124
|
|
|
125
|
+
console.log(widgetInstance, 'widget instance');
|
|
128
126
|
if (!widgetInstance) {
|
|
129
127
|
init({});
|
|
130
128
|
}
|
|
@@ -132,9 +130,11 @@ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
|
|
|
132
130
|
|
|
133
131
|
// Run after DOM is ready
|
|
134
132
|
if (document.readyState === 'loading') {
|
|
135
|
-
document.addEventListener('DOMContentLoaded', autoInit);
|
|
133
|
+
document.addEventListener('DOMContentLoaded - WIDGET', autoInit);
|
|
136
134
|
} else {
|
|
137
135
|
// DOM already loaded, init immediately
|
|
136
|
+
|
|
137
|
+
console.log('load document - WIDGET');
|
|
138
138
|
autoInit();
|
|
139
139
|
}
|
|
140
140
|
}
|