@archbee/app-widget 1.1.0 → 1.1.2

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
@@ -53,10 +53,10 @@ Can also be used with ref for a more programmatic approach:
53
53
 
54
54
  ```tsx
55
55
  import React from 'react';
56
- import { ArchbeeAppWidget, ArchbeeWidget } from '@archbee/app-widget'
56
+ import { ArchbeeAppWidget, AbWidgetRef } from '@archbee/app-widget'
57
57
 
58
58
  function App() {
59
- const widgetRef = useRef<ArchbeeWidget>(null);
59
+ const widgetRef = useRef<AbWidgetRef>(null);
60
60
 
61
61
  return (
62
62
  <div>
@@ -96,9 +96,6 @@ ReactDOM.render(<App />, appElement);
96
96
 
97
97
  If `ref` is not passed to `ArchbeeAppWidget`, the children will automatically open the modal popup upon click.
98
98
 
99
- You can find more examples in the `examples` directory, which you can run in a
100
- local development server using `npm start` or `yarn run start`.
101
-
102
99
  ## Demos
103
100
 
104
101
  Down below is a demo setup in [CodePen](https://codepen.io), which
package/index.js ADDED
@@ -0,0 +1,480 @@
1
+ var $hXgUO$reactjsxruntime = require("react/jsx-runtime");
2
+ var $hXgUO$react = require("react");
3
+ var $hXgUO$reactdom = require("react-dom");
4
+ var $hXgUO$reactmodal = require("react-modal");
5
+
6
+
7
+ function $parcel$export(e, n, v, s) {
8
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
9
+ }
10
+
11
+ function $parcel$interopDefault(a) {
12
+ return a && a.__esModule ? a.default : a;
13
+ }
14
+
15
+ $parcel$export(module.exports, "ArchbeeAppWidget", function () { return $3454c312fc43187e$export$d1cc455138316794; });
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+ const $7d0ac34aa5949d25$export$15a92cf792322942 = {
29
+ animation: "pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite"
30
+ };
31
+
32
+
33
+ const $24a1ab1d9e5e268a$export$7428da3cfb78ae6 = ({ onClose: onClose })=>{
34
+ const eventStopPropagation = (event)=>{
35
+ event.preventDefault();
36
+ event.stopPropagation();
37
+ };
38
+ return /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("div", {
39
+ onClick: onClose,
40
+ className: "ab-doc-container",
41
+ children: /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsxs)("div", {
42
+ onClick: eventStopPropagation,
43
+ className: "ab-doc-loader",
44
+ children: [
45
+ /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("div", {
46
+ className: "ab-rounded ab-gray w-1/2 mb-4",
47
+ style: {
48
+ ...(0, $7d0ac34aa5949d25$export$15a92cf792322942),
49
+ height: "3rem"
50
+ }
51
+ }),
52
+ /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("div", {
53
+ className: "ab-rounded ab-gray ab-mb-20",
54
+ style: {
55
+ ...(0, $7d0ac34aa5949d25$export$15a92cf792322942),
56
+ height: "1.75rem",
57
+ width: "100%"
58
+ }
59
+ }),
60
+ /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("div", {
61
+ className: "ab-rounded ab-gray ab-mb-20",
62
+ style: {
63
+ ...(0, $7d0ac34aa5949d25$export$15a92cf792322942),
64
+ height: "1.75rem",
65
+ width: "75%"
66
+ }
67
+ }),
68
+ /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("div", {
69
+ className: "ab-rounded ab-gray ab-mb-20",
70
+ style: {
71
+ ...(0, $7d0ac34aa5949d25$export$15a92cf792322942),
72
+ height: "1.75rem",
73
+ width: "75%"
74
+ }
75
+ }),
76
+ /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("div", {
77
+ className: "ab-rounded ab-gray ab-mb-20",
78
+ style: {
79
+ ...(0, $7d0ac34aa5949d25$export$15a92cf792322942),
80
+ height: "2.5rem",
81
+ width: "25%"
82
+ }
83
+ }),
84
+ /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("div", {
85
+ className: "ab-rounded ab-gray ab-mb-20",
86
+ style: {
87
+ ...(0, $7d0ac34aa5949d25$export$15a92cf792322942),
88
+ height: "1.75rem",
89
+ width: "60%"
90
+ }
91
+ }),
92
+ /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("div", {
93
+ className: "ab-rounded ab-gray ab-mb-20",
94
+ style: {
95
+ ...(0, $7d0ac34aa5949d25$export$15a92cf792322942),
96
+ height: "1.75rem",
97
+ width: "40%"
98
+ }
99
+ }),
100
+ /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("div", {
101
+ className: "ab-rounded ab-gray ab-mb-20",
102
+ style: {
103
+ ...(0, $7d0ac34aa5949d25$export$15a92cf792322942),
104
+ height: "1.75rem",
105
+ width: "100%"
106
+ }
107
+ }),
108
+ /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("div", {
109
+ className: "ab-rounded ab-gray ab-mb-20",
110
+ style: {
111
+ ...(0, $7d0ac34aa5949d25$export$15a92cf792322942),
112
+ height: "1.75rem",
113
+ width: "80%"
114
+ }
115
+ }),
116
+ /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("div", {
117
+ className: "ab-rounded ab-gray",
118
+ style: {
119
+ ...(0, $7d0ac34aa5949d25$export$15a92cf792322942),
120
+ height: "1.75rem",
121
+ width: "25%"
122
+ }
123
+ })
124
+ ]
125
+ })
126
+ });
127
+ };
128
+
129
+
130
+
131
+
132
+
133
+ const $671c57dd09bd5436$export$e9f7c27668489a52 = ({ onClose: onClose })=>{
134
+ const eventStopPropagation = (event)=>{
135
+ event.preventDefault();
136
+ event.stopPropagation();
137
+ };
138
+ return /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("div", {
139
+ onClick: onClose,
140
+ className: "ab-doc-search-container",
141
+ children: /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("div", {
142
+ onClick: eventStopPropagation,
143
+ className: "ab-doc-search-placeholder",
144
+ children: /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("div", {
145
+ className: "ab-rounded ab-gray",
146
+ style: {
147
+ ...(0, $7d0ac34aa5949d25$export$15a92cf792322942),
148
+ height: "3rem",
149
+ width: "96%"
150
+ }
151
+ })
152
+ })
153
+ });
154
+ };
155
+
156
+
157
+ const $d0b8a7ae25f50023$export$a65e3ebe24ca6cb5 = ({ spaceId: spaceId, docId: docId, screen: screen = "docs", jwt: jwt, shareableToken: shareableToken, onClose: onClose })=>{
158
+ var _iframeRef_current;
159
+ const iframeRef = (0, $hXgUO$react.useRef)(null);
160
+ const onIframeLoaded = ()=>{
161
+ const elementId = screen === "docs" ? "ab-doc-placeholder-container" : "ab-search-placeholder-container";
162
+ const element = document.getElementById(elementId);
163
+ element === null || element === void 0 ? void 0 : element.remove();
164
+ };
165
+ (0, $hXgUO$react.useEffect)(()=>{
166
+ if (!iframeRef.current) return;
167
+ const url = $d0b8a7ae25f50023$var$getIframeUrl(spaceId, docId, jwt, shareableToken, screen);
168
+ iframeRef.current.src = url;
169
+ }, [
170
+ screen,
171
+ spaceId,
172
+ docId,
173
+ jwt,
174
+ shareableToken
175
+ ]);
176
+ return /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsxs)("div", {
177
+ onClick: onClose,
178
+ className: "ab-modal-container",
179
+ children: [
180
+ screen === "docs" && /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("div", {
181
+ id: "ab-doc-placeholder-container",
182
+ className: "ab-placeholder-wrapper",
183
+ children: /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)((0, $24a1ab1d9e5e268a$export$7428da3cfb78ae6), {
184
+ onClose: onClose
185
+ })
186
+ }),
187
+ screen === "search" && /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("div", {
188
+ id: "ab-search-placeholder-container",
189
+ className: "ab-placeholder-wrapper",
190
+ children: /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)((0, $671c57dd09bd5436$export$e9f7c27668489a52), {
191
+ onClose: onClose
192
+ })
193
+ }),
194
+ /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("iframe", {
195
+ onLoad: onIframeLoaded,
196
+ ref: iframeRef,
197
+ title: "Archbee widget",
198
+ src: (_iframeRef_current = iframeRef.current) === null || _iframeRef_current === void 0 ? void 0 : _iframeRef_current.src,
199
+ className: "ab-modal-iframe"
200
+ })
201
+ ]
202
+ });
203
+ };
204
+ const $d0b8a7ae25f50023$var$getIframeUrl = (spaceId, docId, jwt, shareableToken, screen)=>{
205
+ let iframeUrl = `${undefined}/${spaceId}`;
206
+ if (docId) iframeUrl = iframeUrl + `/${docId}`;
207
+ const template = "?template=widget";
208
+ iframeUrl += template;
209
+ if (jwt) iframeUrl += `&jwt=${jwt}`;
210
+ if (shareableToken) iframeUrl += `&shareableToken=${shareableToken}`;
211
+ if (screen) iframeUrl += `&initialScreen=${screen}`;
212
+ return iframeUrl;
213
+ };
214
+
215
+
216
+ var $5ea18ff364e1e223$export$e923c830cbf8e49c;
217
+ (function(EVENT_TYPE_ENUM) {
218
+ EVENT_TYPE_ENUM["init"] = "init";
219
+ EVENT_TYPE_ENUM["showWidget"] = "show-widget";
220
+ EVENT_TYPE_ENUM["hideWidget"] = "hide-widget";
221
+ })($5ea18ff364e1e223$export$e923c830cbf8e49c || ($5ea18ff364e1e223$export$e923c830cbf8e49c = {}));
222
+ const $5ea18ff364e1e223$export$fddb3f5bc79c4a16 = [
223
+ "init",
224
+ "show-widget",
225
+ "hide-widget"
226
+ ];
227
+ const $5ea18ff364e1e223$export$4eadcc42fc7554ad = ()=>{
228
+ if (typeof window === "undefined") return;
229
+ return new CustomEvent("show-widget");
230
+ };
231
+ const $5ea18ff364e1e223$export$c6414d05a79532c3 = ()=>{
232
+ if (typeof window === "undefined") return;
233
+ return new CustomEvent("hide-widget");
234
+ };
235
+
236
+
237
+ const $91b786905c14e19d$export$86fbec116b87613f = ()=>{
238
+ const [isModalOpen, setIsModalOpen] = (0, $hXgUO$react.useState)(false);
239
+ const [docId, setDocId] = (0, $hXgUO$react.useState)();
240
+ const [jwt, setJwt] = (0, $hXgUO$react.useState)();
241
+ const [shareableToken, setShareableToken] = (0, $hXgUO$react.useState)();
242
+ const [initialScreen, setInitialScreen] = (0, $hXgUO$react.useState)();
243
+ const widgetActionListener = (0, $hXgUO$react.useCallback)(()=>{
244
+ setIsModalOpen(window._archbee.widget.isOpen);
245
+ setDocId(window._archbee.widget.docId);
246
+ setJwt(window._archbee.widget.jwt);
247
+ setShareableToken(window._archbee.widget.shareableToken);
248
+ setInitialScreen(window._archbee.widget.widgetType);
249
+ const widget = document.getElementsByClassName("ab-widget");
250
+ if (!widget.length) return;
251
+ if (window._archbee.widget.isOpen) widget[0].removeAttribute("style");
252
+ else widget[0].setAttribute("style", "visibility: hidden");
253
+ }, []);
254
+ const onPostMessageReceived = (0, $hXgUO$react.useCallback)(({ data: data })=>{
255
+ if (data.source !== "archbee-widget") return;
256
+ switch(data.type){
257
+ case "ab-doc-close":
258
+ closeModal();
259
+ break;
260
+ default:
261
+ break;
262
+ }
263
+ }, []);
264
+ (0, $hXgUO$react.useEffect)(()=>{
265
+ window.addEventListener((0, $5ea18ff364e1e223$export$e923c830cbf8e49c).showWidget, widgetActionListener);
266
+ window.addEventListener((0, $5ea18ff364e1e223$export$e923c830cbf8e49c).hideWidget, widgetActionListener);
267
+ window.addEventListener("message", onPostMessageReceived);
268
+ return ()=>{
269
+ window.removeEventListener((0, $5ea18ff364e1e223$export$e923c830cbf8e49c).showWidget, widgetActionListener);
270
+ window.removeEventListener((0, $5ea18ff364e1e223$export$e923c830cbf8e49c).hideWidget, widgetActionListener);
271
+ window.removeEventListener("message", onPostMessageReceived);
272
+ };
273
+ }, [
274
+ widgetActionListener,
275
+ onPostMessageReceived
276
+ ]);
277
+ const closeModal = ()=>{
278
+ window._archbee.widget.isOpen = false;
279
+ window._archbee.widget.docId = undefined;
280
+ window.dispatchEvent((0, $5ea18ff364e1e223$export$c6414d05a79532c3)());
281
+ };
282
+ (0, $hXgUO$react.useEffect)(()=>{
283
+ (0, ($parcel$interopDefault($hXgUO$reactmodal))).setAppElement("#archbee-docs-widget-modal");
284
+ }, []);
285
+ return /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("div", {
286
+ id: "archbee-docs-widget-modal",
287
+ children: isModalOpen && /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)((0, $d0b8a7ae25f50023$export$a65e3ebe24ca6cb5), {
288
+ docId: docId || "",
289
+ spaceId: window._archbee.widget.spaceId || window._archbee.widget.collectionId || "",
290
+ jwt: jwt,
291
+ shareableToken: shareableToken,
292
+ screen: initialScreen,
293
+ onClose: closeModal
294
+ })
295
+ });
296
+ };
297
+ var $91b786905c14e19d$export$2e2bcd8739ae039 = $91b786905c14e19d$export$86fbec116b87613f;
298
+
299
+
300
+ const $a328aa60f920ce82$export$b3890eb0ae9dca99 = (cb)=>{
301
+ const element = document.getElementsByClassName("ab-widget")[0];
302
+ (0, ($parcel$interopDefault($hXgUO$reactdom))).render(/*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)((0, ($parcel$interopDefault($hXgUO$react))).StrictMode, {
303
+ children: /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)((0, $91b786905c14e19d$export$2e2bcd8739ae039), {})
304
+ }), element, ()=>cb && cb(element));
305
+ };
306
+
307
+
308
+
309
+ const $9913b3312051bc1e$export$e41ef1391ce9e919 = (widget)=>{
310
+ window._archbee.widget = {
311
+ ...widget
312
+ };
313
+ window._archbee.widget.isOpen = false;
314
+ };
315
+ const $9913b3312051bc1e$export$18d0fd55b1b3892d = (widg, render)=>{
316
+ if (typeof document.addEventListener !== "function") return;
317
+ window._archbee.widget = {
318
+ ...window._archbee.widget,
319
+ ...widg
320
+ };
321
+ try {
322
+ render(widg.onRenderFinish);
323
+ } catch (err) {
324
+ console.log(err);
325
+ }
326
+ };
327
+ const $9913b3312051bc1e$export$26ae5ca175b4ec5a = ()=>{
328
+ if (document.getElementsByClassName("ab-widget").length) return;
329
+ const abDiv = document.createElement("div");
330
+ abDiv.style.cssText = "visibility:hidden";
331
+ abDiv.className = `ab-widget ab-id-${Date.now()}`;
332
+ document.body.appendChild(abDiv);
333
+ };
334
+
335
+
336
+ const $12e413341357248b$export$5cfe1e4796fafad8 = ()=>{
337
+ if (!("Proxy" in window)) {
338
+ console.warn("Your browser doesn't support Proxies.");
339
+ return;
340
+ }
341
+ const proxy = new Proxy(window._archbee.queue, {
342
+ get (target, property, receiver) {
343
+ return Reflect.get(target, property, receiver);
344
+ },
345
+ apply (target, thisArg, argumentsList) {
346
+ return thisArg[target].apply(this, argumentsList);
347
+ },
348
+ set (target, property, value) {
349
+ $12e413341357248b$export$403ad7fb28be9f07(target);
350
+ return Reflect.set(target, property, value);
351
+ },
352
+ deleteProperty (target, property) {
353
+ return Reflect.deleteProperty(target, property);
354
+ }
355
+ });
356
+ return proxy;
357
+ };
358
+ const $12e413341357248b$export$403ad7fb28be9f07 = (proxy)=>{
359
+ if (!proxy.length) return;
360
+ proxy.forEach((event, index)=>{
361
+ // keep this here for now
362
+ console.log("widget event received:", event.eventType, window._archbee.widget);
363
+ if (event.hasExecuted || !(0, $5ea18ff364e1e223$export$fddb3f5bc79c4a16).includes(event.eventType)) {
364
+ proxy.splice(index, 1);
365
+ return;
366
+ }
367
+ if (event.eventType === (0, $5ea18ff364e1e223$export$e923c830cbf8e49c).init) {
368
+ (0, $9913b3312051bc1e$export$e41ef1391ce9e919)(event);
369
+ (0, $9913b3312051bc1e$export$18d0fd55b1b3892d)(event, (0, $a328aa60f920ce82$export$b3890eb0ae9dca99));
370
+ }
371
+ if (event.eventType === (0, $5ea18ff364e1e223$export$e923c830cbf8e49c).showWidget) {
372
+ window._archbee.widget.isOpen = true;
373
+ if (event.docId) window._archbee.widget.docId = event.docId;
374
+ if (event.widgetType) {
375
+ const widgetType = event.docId && event.widgetType === "search" ? "docs" : event.widgetType;
376
+ window._archbee.widget.widgetType = widgetType;
377
+ } else window._archbee.widget.widgetType = "docs";
378
+ window.dispatchEvent((0, $5ea18ff364e1e223$export$4eadcc42fc7554ad)());
379
+ }
380
+ if (event.eventType === (0, $5ea18ff364e1e223$export$e923c830cbf8e49c).hideWidget) {
381
+ window._archbee.widget.isOpen = false;
382
+ window._archbee.widget.docId = undefined;
383
+ window._archbee.widget.widgetType = undefined;
384
+ window.dispatchEvent((0, $5ea18ff364e1e223$export$c6414d05a79532c3)());
385
+ }
386
+ event.hasExecuted = true;
387
+ });
388
+ };
389
+
390
+
391
+
392
+ const $ef43c9dfc50ce6f2$export$b66f8e2563088683 = ()=>{
393
+ var _link_parentNode;
394
+ const widgetcsslink = document.createElement("link");
395
+ const link = document.getElementsByTagName("link")[0];
396
+ widgetcsslink["rel"] = "stylesheet";
397
+ widgetcsslink["href"] = `${"https://widget.archbee.com/v1"}/index.css`;
398
+ if (!link) document.getElementsByTagName("head")[0].append(widgetcsslink);
399
+ link === null || link === void 0 ? void 0 : (_link_parentNode = link.parentNode) === null || _link_parentNode === void 0 ? void 0 : _link_parentNode.appendChild(widgetcsslink);
400
+ };
401
+ const $ef43c9dfc50ce6f2$export$daaeb3f1095d12b8 = (loadingStrategy)=>{
402
+ var _script_parentNode;
403
+ const mainUrl = "https://widget.archbee.com/v1";
404
+ let scripttag = document.createElement("script");
405
+ scripttag["async"] = loadingStrategy === "lazy";
406
+ scripttag["src"] = `${mainUrl}/index.js`;
407
+ const script = document.getElementsByTagName("script")[0];
408
+ script === null || script === void 0 ? void 0 : (_script_parentNode = script.parentNode) === null || _script_parentNode === void 0 ? void 0 : _script_parentNode.insertBefore(scripttag, script);
409
+ };
410
+ const $ef43c9dfc50ce6f2$export$2d47b06a7861ac47 = (spaceId, jwt, shareableToken, loadingStrategy = "lazy")=>{
411
+ if (!window._archbee) {
412
+ // @ts-expect-error
413
+ window._archbee = window._archbee || {
414
+ queue: [],
415
+ push: function(event) {
416
+ window._archbee.queue.push(event);
417
+ }
418
+ };
419
+ window._archbee.push({
420
+ eventType: "init",
421
+ spaceId: spaceId,
422
+ jwt: jwt,
423
+ shareableToken: shareableToken
424
+ });
425
+ $ef43c9dfc50ce6f2$export$daaeb3f1095d12b8(loadingStrategy);
426
+ }
427
+ return window._archbee;
428
+ };
429
+
430
+
431
+
432
+
433
+ const $3454c312fc43187e$export$d1cc455138316794 = /*#__PURE__*/ (0, $hXgUO$react.forwardRef)(({ className: className, spaceId: spaceId, jwt: jwt, shareableToken: shareableToken, docId: docId, widgetType: widgetType = "docs", loadingStrategy: loadingStrategy = "lazy", onWidgetOpen: onWidgetOpen, onWidgetClose: onWidgetClose, children: children }, ref)=>{
434
+ const elementRef = (0, $hXgUO$react.useRef)(null);
435
+ const widgetInstance = (0, $hXgUO$react.useMemo)(()=>{
436
+ if (typeof window === "undefined") return;
437
+ return (0, $ef43c9dfc50ce6f2$export$2d47b06a7861ac47)(spaceId, jwt, shareableToken, loadingStrategy);
438
+ }, [
439
+ spaceId,
440
+ jwt,
441
+ shareableToken,
442
+ loadingStrategy
443
+ ]);
444
+ (0, $hXgUO$react.useImperativeHandle)(ref, ()=>{
445
+ return {
446
+ open: onOpenWidget,
447
+ close: onCloseWidget,
448
+ instance: ()=>widgetInstance
449
+ };
450
+ });
451
+ const onOpenWidget = ()=>{
452
+ widgetInstance === null || widgetInstance === void 0 ? void 0 : widgetInstance.push({
453
+ eventType: "show-widget",
454
+ widgetType: widgetType,
455
+ docId: docId
456
+ });
457
+ onWidgetOpen === null || onWidgetOpen === void 0 ? void 0 : onWidgetOpen();
458
+ };
459
+ const onCloseWidget = ()=>{
460
+ widgetInstance === null || widgetInstance === void 0 ? void 0 : widgetInstance.push({
461
+ eventType: "hide-widget"
462
+ });
463
+ onWidgetClose === null || onWidgetClose === void 0 ? void 0 : onWidgetClose();
464
+ };
465
+ const onElementClicked = (event)=>{
466
+ var _elementRef_current;
467
+ if (typeof window !== "undefined" && ((_elementRef_current = elementRef.current) === null || _elementRef_current === void 0 ? void 0 : _elementRef_current.contains(event.target)) && !ref) {
468
+ event.preventDefault();
469
+ onOpenWidget();
470
+ }
471
+ };
472
+ return /*#__PURE__*/ (0, $hXgUO$reactjsxruntime.jsx)("div", {
473
+ className: className !== null && className !== void 0 ? className : "",
474
+ ref: elementRef,
475
+ onClick: onElementClicked,
476
+ children: children
477
+ });
478
+ });
479
+
480
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archbee/app-widget",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "private": false,
5
5
  "license": "UNLICENSED",
6
6
  "author": {
@@ -14,6 +14,9 @@
14
14
  "react": "^18.2.0",
15
15
  "react-dom": "^18.2.0"
16
16
  },
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
17
20
  "devDependencies": {
18
21
  "@babel/plugin-proposal-private-property-in-object": "^7.21.11",
19
22
  "@craco/craco": "^7.1.0",
@@ -67,5 +70,6 @@
67
70
  "last 1 firefox version",
68
71
  "last 1 safari version"
69
72
  ]
70
- }
73
+ },
74
+ "types": "types.d.ts"
71
75
  }
package/types.d.ts ADDED
@@ -0,0 +1,60 @@
1
+ import React from "react";
2
+ declare global {
3
+ interface Window {
4
+ _archbee: ArchbeeWidgetInstance;
5
+ }
6
+ }
7
+ interface ArchbeeWidgetInstance {
8
+ version: string;
9
+ widget: AbWidgetData;
10
+ queue: any;
11
+ push: Function;
12
+ }
13
+ enum EVENT_TYPE_ENUM {
14
+ init = "init",
15
+ showWidget = "show-widget",
16
+ hideWidget = "hide-widget"
17
+ }
18
+ type WidgetEventType = EVENT_TYPE_ENUM.init | EVENT_TYPE_ENUM.showWidget | EVENT_TYPE_ENUM.hideWidget;
19
+ interface AbWidgetData {
20
+ eventType: WidgetEventType;
21
+ collectionId?: string;
22
+ spaceId?: string;
23
+ docId?: string;
24
+ isOpen: boolean;
25
+ selector: string;
26
+ origin?: string;
27
+ onRenderFinish?: Function;
28
+ hasExecuted: boolean;
29
+ jwt?: string;
30
+ shareableToken?: string;
31
+ widgetType?: ScreenType;
32
+ }
33
+ type ScreenType = 'docs' | 'search';
34
+ export interface AbWidgetRef {
35
+ open: () => void;
36
+ close: () => void;
37
+ instance: () => ArchbeeWidgetInstance;
38
+ }
39
+ type Props = {
40
+ spaceId: string;
41
+ docId?: string;
42
+ jwt?: string;
43
+ className?: string;
44
+ shareableToken?: string;
45
+ widgetType: ScreenType;
46
+ user?: {
47
+ id: string;
48
+ email?: string;
49
+ first_name?: string;
50
+ last_name?: string;
51
+ profile_image_url?: string;
52
+ [key: string]: any;
53
+ };
54
+ loadingStrategy?: 'eager' | 'lazy';
55
+ onWidgetOpen?: Function;
56
+ onWidgetClose?: Function;
57
+ };
58
+ export const ArchbeeAppWidget: React.ForwardRefExoticComponent<Props & {
59
+ children?: React.ReactNode;
60
+ } & React.RefAttributes<AbWidgetRef>>;