@archbee/app-widget 1.1.12 → 1.1.14

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