open-chat-studio-widget 0.1.0 → 0.2.0

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.
Files changed (35) hide show
  1. package/README.md +21 -50
  2. package/dist/cjs/{index-3826e5a2.js → index-550ac5f9.js} +68 -85
  3. package/dist/cjs/index-550ac5f9.js.map +1 -0
  4. package/dist/cjs/loader.cjs.js +2 -2
  5. package/dist/cjs/open-chat-studio-widget.cjs.entry.js +75 -8
  6. package/dist/cjs/open-chat-studio-widget.cjs.entry.js.map +1 -1
  7. package/dist/cjs/open-chat-studio-widget.cjs.js +2 -2
  8. package/dist/collection/components/ocs-chat/heroicons.js +20 -0
  9. package/dist/collection/components/ocs-chat/heroicons.js.map +1 -0
  10. package/dist/collection/components/ocs-chat/ocs-chat.css +377 -431
  11. package/dist/collection/components/ocs-chat/ocs-chat.js +94 -11
  12. package/dist/collection/components/ocs-chat/ocs-chat.js.map +1 -1
  13. package/dist/components/open-chat-studio-widget.js +78 -9
  14. package/dist/components/open-chat-studio-widget.js.map +1 -1
  15. package/dist/esm/{index-9a12ccff.js → index-3870d3ba.js} +68 -85
  16. package/dist/esm/index-3870d3ba.js.map +1 -0
  17. package/dist/esm/loader.js +3 -3
  18. package/dist/esm/open-chat-studio-widget.entry.js +75 -8
  19. package/dist/esm/open-chat-studio-widget.entry.js.map +1 -1
  20. package/dist/esm/open-chat-studio-widget.js +3 -3
  21. package/dist/open-chat-studio-widget/open-chat-studio-widget.esm.js +1 -1
  22. package/dist/open-chat-studio-widget/open-chat-studio-widget.esm.js.map +1 -1
  23. package/dist/open-chat-studio-widget/p-216e7afd.entry.js +2 -0
  24. package/dist/open-chat-studio-widget/p-216e7afd.entry.js.map +1 -0
  25. package/dist/open-chat-studio-widget/p-a0561deb.js +3 -0
  26. package/dist/{esm/index-9a12ccff.js.map → open-chat-studio-widget/p-a0561deb.js.map} +1 -1
  27. package/dist/types/components/ocs-chat/heroicons.d.ts +6 -0
  28. package/dist/types/components/ocs-chat/ocs-chat.d.ts +21 -1
  29. package/dist/types/components.d.ts +36 -2
  30. package/package.json +8 -3
  31. package/dist/cjs/index-3826e5a2.js.map +0 -1
  32. package/dist/open-chat-studio-widget/p-b1996f7e.entry.js +0 -2
  33. package/dist/open-chat-studio-widget/p-b1996f7e.entry.js.map +0 -1
  34. package/dist/open-chat-studio-widget/p-d346075a.js +0 -3
  35. package/dist/open-chat-studio-widget/p-d346075a.js.map +0 -1
package/README.md CHANGED
@@ -1,62 +1,33 @@
1
- # Open Chat Studio Chat Component
1
+ # Open Chat Studio Chat Widget
2
2
 
3
- A Web Component built with [Stencil](https://stenciljs.com/) that allows you to add a chat dialog to a web page
4
- that is connected to a public Open Chat Studio (OCS) bot.
3
+ A chatbot component for Open Chat Studio.
5
4
 
6
- ## Getting Started
5
+ For more information, see the [Open Chat Studio documentation](https://dimagi.github.io/open-chat-studio-docs/how-to/embed/)
7
6
 
8
- To try this component out, run:
7
+ <!-- Auto Generated Below -->
9
8
 
10
- ```bash
11
- npm install
12
- npm start
13
- ```
14
9
 
15
- Now load the localhost URL shown in the console in your browser.
10
+ ## Properties
16
11
 
17
- Note that this requires you to have OCS running locally on port 8000.
18
- You will also need to set the `boturl` property on the `open-chat-studio-widget` element to the URL of a bot you have
19
- running locally.
12
+ | Property | Attribute | Description | Type | Default |
13
+ | --------------------- | ------------- | ------------------------------------------------------ | ------------------------------- | ----------- |
14
+ | `botUrl` _(required)_ | `bot-url` | The URL of the bot to connect to. | `string` | `undefined` |
15
+ | `buttonText` | `button-text` | The text to display on the button. | `string` | `"Chat"` |
16
+ | `expanded` | `expanded` | Whether the chat widget is initially expanded. | `boolean` | `false` |
17
+ | `position` | `position` | The initial position of the chat widget on the screen. | `"center" \| "left" \| "right"` | `'right'` |
18
+ | `visible` | `visible` | Whether the chat widget is visible on load. | `boolean` | `false` |
20
19
 
21
- To build the component for production, run:
22
20
 
23
- ```bash
24
- npm run build
25
- ```
21
+ ## CSS Custom Properties
26
22
 
27
- To run the unit tests for the components, run:
23
+ | Name | Description |
24
+ | --------------------------------- | -------------------------------- |
25
+ | `--button-background-color` | Button background color |
26
+ | `--button-background-color-hover` | Button background color on hover |
27
+ | `--button-text-color` | Button text color |
28
+ | `--button-text-color-hover` | Button text color on hover |
28
29
 
29
- ```bash
30
- npm test
31
- ```
32
30
 
33
- ## Making Changes
31
+ ----------------------------------------------
34
32
 
35
- To make changes to the component, you can edit the files in the `src/components/open-chat-studio-widget` directory. You can
36
- also edit the `src/index.html` file to change the page that is loaded when you run `npm start`.
37
-
38
- ### Styling
39
-
40
- The component uses [Tailwind CSS](https://tailwindcss.com/) with [DaisyUI](https://daisyui.com/) for styling.
41
-
42
- ## Using this component
43
-
44
- There are three strategies we recommend for using web components built with Stencil.
45
-
46
- The first step for all three of these strategies is to [publish to NPM](https://docs.npmjs.com/getting-started/publishing-npm-packages).
47
-
48
- Once you've set up your local npm account, can do this by running
49
-
50
- ```
51
- npm publish
52
- ```
53
-
54
- ### Script tag
55
-
56
- - Put a script tag similar to this `<script type='module' src='https://unpkg.com/open-chat-studio-widget@0.0.1/dist/open-chat-studio-widget.esm.js'></script>` in the head of your index.html
57
- - Then you can use the element anywhere in your template, JSX, html etc
58
-
59
- ### Node Modules
60
- - Run `npm install open-chat-studio-widget --save`
61
- - Put a script tag similar to this `<script type='module' src='node_modules/open-chat-studio-widget/dist/open-chat-studio-widget.esm.js'></script>` in the head of your index.html
62
- - Then you can use the element anywhere in your template, JSX, html etc
33
+ *Built with [StencilJS](https://stenciljs.com/)*
@@ -21,7 +21,7 @@ function _interopNamespace(e) {
21
21
  }
22
22
 
23
23
  const NAMESPACE = 'open-chat-studio-widget';
24
- const BUILD = /* open-chat-studio-widget */ { allRenderFn: true, appendChildSlotFix: false, asyncLoading: true, asyncQueue: false, attachStyles: true, cloneNodeFix: false, cmpDidLoad: false, cmpDidRender: false, cmpDidUnload: false, cmpDidUpdate: false, cmpShouldUpdate: false, cmpWillLoad: true, cmpWillRender: false, cmpWillUpdate: false, connectedCallback: false, constructableCSS: true, cssAnnotations: true, devTools: false, disconnectedCallback: false, element: false, event: false, experimentalScopedSlotChanges: false, experimentalSlotFixes: false, formAssociated: false, hasRenderFn: true, hostListener: false, hostListenerTarget: false, hostListenerTargetBody: false, hostListenerTargetDocument: false, hostListenerTargetParent: false, hostListenerTargetWindow: false, hotModuleReplacement: false, hydrateClientSide: false, hydrateServerSide: false, hydratedAttribute: false, hydratedClass: true, hydratedSelectorName: "hydrated", initializeNextTick: false, invisiblePrehydration: true, isDebug: false, isDev: false, isTesting: false, lazyLoad: true, lifecycle: true, lifecycleDOMEvents: false, member: true, method: false, mode: false, modernPropertyDecls: false, observeAttribute: true, profile: false, prop: true, propBoolean: true, propMutable: true, propNumber: false, propString: true, reflect: false, scoped: false, scopedSlotTextContentFix: false, scriptDataOpts: false, shadowDelegatesFocus: false, shadowDom: true, slot: false, slotChildNodesFix: false, slotRelocation: false, state: true, style: true, svg: false, taskQueue: true, transformTagName: false, updatable: true, vdomAttribute: true, vdomClass: true, vdomFunctional: false, vdomKey: true, vdomListener: true, vdomPropOrAttr: true, vdomRef: true, vdomRender: true, vdomStyle: true, vdomText: true, vdomXlink: true, watchCallback: false };
24
+ const BUILD = /* open-chat-studio-widget */ { allRenderFn: true, appendChildSlotFix: false, asyncLoading: true, asyncQueue: false, attachStyles: true, cloneNodeFix: false, cmpDidLoad: false, cmpDidRender: false, cmpDidUnload: false, cmpDidUpdate: false, cmpShouldUpdate: false, cmpWillLoad: true, cmpWillRender: false, cmpWillUpdate: false, connectedCallback: false, constructableCSS: true, cssAnnotations: true, devTools: false, disconnectedCallback: false, element: false, event: false, experimentalScopedSlotChanges: false, experimentalSlotFixes: false, formAssociated: false, hasRenderFn: true, hostListener: false, hostListenerTarget: false, hostListenerTargetBody: false, hostListenerTargetDocument: false, hostListenerTargetParent: false, hostListenerTargetWindow: false, hotModuleReplacement: false, hydrateClientSide: false, hydrateServerSide: false, hydratedAttribute: false, hydratedClass: true, hydratedSelectorName: "hydrated", initializeNextTick: false, invisiblePrehydration: true, isDebug: false, isDev: false, isTesting: false, lazyLoad: true, lifecycle: true, lifecycleDOMEvents: false, member: true, method: false, mode: false, modernPropertyDecls: false, observeAttribute: true, profile: false, prop: true, propBoolean: true, propMutable: true, propNumber: false, propString: true, reflect: false, scoped: false, scopedSlotTextContentFix: false, scriptDataOpts: false, shadowDelegatesFocus: false, shadowDom: true, slot: false, slotChildNodesFix: false, slotRelocation: false, state: true, style: true, svg: true, taskQueue: true, transformTagName: false, updatable: true, vdomAttribute: true, vdomClass: true, vdomFunctional: true, vdomKey: false, vdomListener: true, vdomPropOrAttr: true, vdomRef: false, vdomRender: true, vdomStyle: false, vdomText: true, vdomXlink: false, watchCallback: false };
25
25
 
26
26
  /*
27
27
  Stencil Client Platform v4.25.3 | MIT Licensed | https://stenciljs.com
@@ -32,6 +32,10 @@ var __export = (target, all) => {
32
32
  __defProp(target, name, { get: all[name], enumerable: true });
33
33
  };
34
34
 
35
+ // src/utils/constants.ts
36
+ var SVG_NS = "http://www.w3.org/2000/svg";
37
+ var HTML_NS = "http://www.w3.org/1999/xhtml";
38
+
35
39
  // src/client/client-host-ref.ts
36
40
  var hostRefs = /* @__PURE__ */ new WeakMap();
37
41
  var getHostRef = (ref) => hostRefs.get(ref);
@@ -93,7 +97,6 @@ var styles = /* @__PURE__ */ new Map();
93
97
  var HYDRATED_STYLE_ID = "sty-id";
94
98
  var HYDRATED_CSS = "{visibility:hidden}.hydrated{visibility:inherit}";
95
99
  var SLOT_FB_CSS = "slot-fb{display:contents}slot-fb[hidden]{display:none}";
96
- var XLINK_NS = "http://www.w3.org/1999/xlink";
97
100
  var win = typeof window !== "undefined" ? window : {};
98
101
  var doc = win.document || { head: {} };
99
102
  var plt = {
@@ -224,7 +227,6 @@ var uniqueTime = (key, measureText) => {
224
227
  };
225
228
  var h = (nodeName, vnodeData, ...children) => {
226
229
  let child = null;
227
- let key = null;
228
230
  let simple = false;
229
231
  let lastSimple = false;
230
232
  const vNodeChildren = [];
@@ -248,9 +250,6 @@ var h = (nodeName, vnodeData, ...children) => {
248
250
  };
249
251
  walk(children);
250
252
  if (vnodeData) {
251
- if (vnodeData.key) {
252
- key = vnodeData.key;
253
- }
254
253
  {
255
254
  const classData = vnodeData.className || vnodeData.class;
256
255
  if (classData) {
@@ -258,14 +257,18 @@ var h = (nodeName, vnodeData, ...children) => {
258
257
  }
259
258
  }
260
259
  }
260
+ if (typeof nodeName === "function") {
261
+ return nodeName(
262
+ vnodeData === null ? {} : vnodeData,
263
+ vNodeChildren,
264
+ vdomFnUtils
265
+ );
266
+ }
261
267
  const vnode = newVNode(nodeName, null);
262
268
  vnode.$attrs$ = vnodeData;
263
269
  if (vNodeChildren.length > 0) {
264
270
  vnode.$children$ = vNodeChildren;
265
271
  }
266
- {
267
- vnode.$key$ = key;
268
- }
269
272
  return vnode;
270
273
  };
271
274
  var newVNode = (tag, text) => {
@@ -279,13 +282,40 @@ var newVNode = (tag, text) => {
279
282
  {
280
283
  vnode.$attrs$ = null;
281
284
  }
282
- {
283
- vnode.$key$ = null;
284
- }
285
285
  return vnode;
286
286
  };
287
287
  var Host = {};
288
288
  var isHost = (node) => node && node.$tag$ === Host;
289
+ var vdomFnUtils = {
290
+ forEach: (children, cb) => children.map(convertToPublic).forEach(cb),
291
+ map: (children, cb) => children.map(convertToPublic).map(cb).map(convertToPrivate)
292
+ };
293
+ var convertToPublic = (node) => ({
294
+ vattrs: node.$attrs$,
295
+ vchildren: node.$children$,
296
+ vkey: node.$key$,
297
+ vname: node.$name$,
298
+ vtag: node.$tag$,
299
+ vtext: node.$text$
300
+ });
301
+ var convertToPrivate = (node) => {
302
+ if (typeof node.vtag === "function") {
303
+ const vnodeData = { ...node.vattrs };
304
+ if (node.vkey) {
305
+ vnodeData.key = node.vkey;
306
+ }
307
+ if (node.vname) {
308
+ vnodeData.name = node.vname;
309
+ }
310
+ return h(node.vtag, vnodeData, ...node.vchildren || []);
311
+ }
312
+ const vnode = newVNode(node.vtag, node.vtext);
313
+ vnode.$attrs$ = node.vattrs;
314
+ vnode.$children$ = node.vchildren;
315
+ vnode.$key$ = node.vkey;
316
+ vnode.$name$ = node.vname;
317
+ return vnode;
318
+ };
289
319
  var parsePropertyValue = (propValue, propType) => {
290
320
  if (propValue != null && !isComplexType(propValue)) {
291
321
  if (propType & 4 /* Boolean */) {
@@ -408,31 +438,6 @@ var setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialRen
408
438
  classList.remove(...oldClasses.filter((c) => c && !newClasses.includes(c)));
409
439
  classList.add(...newClasses.filter((c) => c && !oldClasses.includes(c)));
410
440
  }
411
- } else if (memberName === "style") {
412
- {
413
- for (const prop in oldValue) {
414
- if (!newValue || newValue[prop] == null) {
415
- if (prop.includes("-")) {
416
- elm.style.removeProperty(prop);
417
- } else {
418
- elm.style[prop] = "";
419
- }
420
- }
421
- }
422
- }
423
- for (const prop in newValue) {
424
- if (!oldValue || newValue[prop] !== oldValue[prop]) {
425
- if (prop.includes("-")) {
426
- elm.style.setProperty(prop, newValue[prop]);
427
- } else {
428
- elm.style[prop] = newValue[prop];
429
- }
430
- }
431
- }
432
- } else if (memberName === "key") ; else if (memberName === "ref") {
433
- if (newValue) {
434
- newValue(elm);
435
- }
436
441
  } else if ((!isProp ) && memberName[0] === "o" && memberName[1] === "n") {
437
442
  if (memberName[2] === "-") {
438
443
  memberName = memberName.slice(3);
@@ -472,26 +477,15 @@ var setAccessor = (elm, memberName, oldValue, newValue, isSvg, flags, initialRen
472
477
  } catch (e) {
473
478
  }
474
479
  }
475
- let xlink = false;
476
- {
477
- if (ln !== (ln = ln.replace(/^xlink\:?/, ""))) {
478
- memberName = ln;
479
- xlink = true;
480
- }
481
- }
482
480
  if (newValue == null || newValue === false) {
483
481
  if (newValue !== false || elm.getAttribute(memberName) === "") {
484
- if (xlink) {
485
- elm.removeAttributeNS(XLINK_NS, memberName);
486
- } else {
482
+ {
487
483
  elm.removeAttribute(memberName);
488
484
  }
489
485
  }
490
486
  } else if ((!isProp || flags & 4 /* isHost */ || isSvg) && !isComplex) {
491
487
  newValue = newValue === true ? "" : newValue;
492
- if (xlink) {
493
- elm.setAttributeNS(XLINK_NS, memberName, newValue);
494
- } else {
488
+ {
495
489
  elm.setAttribute(memberName, newValue);
496
490
  }
497
491
  }
@@ -559,9 +553,16 @@ var createElm = (oldParentVNode, newParentVNode, childIndex) => {
559
553
  if (newVNode2.$text$ !== null) {
560
554
  elm = newVNode2.$elm$ = doc.createTextNode(newVNode2.$text$);
561
555
  } else {
562
- elm = newVNode2.$elm$ = doc.createElement(
556
+ if (!isSvgMode) {
557
+ isSvgMode = newVNode2.$tag$ === "svg";
558
+ }
559
+ elm = newVNode2.$elm$ = doc.createElementNS(
560
+ isSvgMode ? SVG_NS : HTML_NS,
563
561
  !useNativeShadowDom && BUILD.slotRelocation && newVNode2.$flags$ & 2 /* isSlotFallback */ ? "slot-fb" : newVNode2.$tag$
564
- );
562
+ ) ;
563
+ if (isSvgMode && newVNode2.$tag$ === "foreignObject") {
564
+ isSvgMode = false;
565
+ }
565
566
  {
566
567
  updateElement(null, newVNode2, isSvgMode);
567
568
  }
@@ -573,6 +574,13 @@ var createElm = (oldParentVNode, newParentVNode, childIndex) => {
573
574
  }
574
575
  }
575
576
  }
577
+ {
578
+ if (newVNode2.$tag$ === "svg") {
579
+ isSvgMode = false;
580
+ } else if (elm.tagName === "foreignObject") {
581
+ isSvgMode = true;
582
+ }
583
+ }
576
584
  }
577
585
  elm["s-hn"] = hostTagName;
578
586
  return elm;
@@ -598,7 +606,6 @@ var removeVnodes = (vnodes, startIdx, endIdx) => {
598
606
  const vnode = vnodes[index];
599
607
  if (vnode) {
600
608
  const elm = vnode.$elm$;
601
- nullifyVNodeRefs(vnode);
602
609
  if (elm) {
603
610
  elm.remove();
604
611
  }
@@ -608,8 +615,6 @@ var removeVnodes = (vnodes, startIdx, endIdx) => {
608
615
  var updateChildren = (parentElm, oldCh, newVNode2, newCh, isInitialRender = false) => {
609
616
  let oldStartIdx = 0;
610
617
  let newStartIdx = 0;
611
- let idxInOld = 0;
612
- let i2 = 0;
613
618
  let oldEndIdx = oldCh.length - 1;
614
619
  let oldStartVnode = oldCh[0];
615
620
  let oldEndVnode = oldCh[oldEndIdx];
@@ -617,7 +622,6 @@ var updateChildren = (parentElm, oldCh, newVNode2, newCh, isInitialRender = fals
617
622
  let newStartVnode = newCh[0];
618
623
  let newEndVnode = newCh[newEndIdx];
619
624
  let node;
620
- let elmToMove;
621
625
  while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
622
626
  if (oldStartVnode == null) {
623
627
  oldStartVnode = oldCh[++oldStartIdx];
@@ -646,26 +650,7 @@ var updateChildren = (parentElm, oldCh, newVNode2, newCh, isInitialRender = fals
646
650
  oldEndVnode = oldCh[--oldEndIdx];
647
651
  newStartVnode = newCh[++newStartIdx];
648
652
  } else {
649
- idxInOld = -1;
650
653
  {
651
- for (i2 = oldStartIdx; i2 <= oldEndIdx; ++i2) {
652
- if (oldCh[i2] && oldCh[i2].$key$ !== null && oldCh[i2].$key$ === newStartVnode.$key$) {
653
- idxInOld = i2;
654
- break;
655
- }
656
- }
657
- }
658
- if (idxInOld >= 0) {
659
- elmToMove = oldCh[idxInOld];
660
- if (elmToMove.$tag$ !== newStartVnode.$tag$) {
661
- node = createElm(oldCh && oldCh[newStartIdx], newVNode2, idxInOld);
662
- } else {
663
- patch(elmToMove, newStartVnode, isInitialRender);
664
- oldCh[idxInOld] = void 0;
665
- node = elmToMove.$elm$;
666
- }
667
- newStartVnode = newCh[++newStartIdx];
668
- } else {
669
654
  node = createElm(oldCh && oldCh[newStartIdx], newVNode2, newStartIdx);
670
655
  newStartVnode = newCh[++newStartIdx];
671
656
  }
@@ -691,9 +676,6 @@ var updateChildren = (parentElm, oldCh, newVNode2, newCh, isInitialRender = fals
691
676
  };
692
677
  var isSameVnode = (leftVNode, rightVNode, isInitialRender = false) => {
693
678
  if (leftVNode.$tag$ === rightVNode.$tag$) {
694
- if (!isInitialRender) {
695
- return leftVNode.$key$ === rightVNode.$key$;
696
- }
697
679
  if (isInitialRender && !leftVNode.$key$ && rightVNode.$key$) {
698
680
  leftVNode.$key$ = rightVNode.$key$;
699
681
  }
@@ -705,8 +687,12 @@ var patch = (oldVNode, newVNode2, isInitialRender = false) => {
705
687
  const elm = newVNode2.$elm$ = oldVNode.$elm$;
706
688
  const oldChildren = oldVNode.$children$;
707
689
  const newChildren = newVNode2.$children$;
690
+ const tag = newVNode2.$tag$;
708
691
  const text = newVNode2.$text$;
709
692
  if (text === null) {
693
+ {
694
+ isSvgMode = tag === "svg" ? true : tag === "foreignObject" ? false : isSvgMode;
695
+ }
710
696
  {
711
697
  {
712
698
  updateElement(oldVNode, newVNode2, isSvgMode);
@@ -725,16 +711,13 @@ var patch = (oldVNode, newVNode2, isInitialRender = false) => {
725
711
  ) {
726
712
  removeVnodes(oldChildren, 0, oldChildren.length - 1);
727
713
  }
714
+ if (isSvgMode && tag === "svg") {
715
+ isSvgMode = false;
716
+ }
728
717
  } else if (oldVNode.$text$ !== text) {
729
718
  elm.data = text;
730
719
  }
731
720
  };
732
- var nullifyVNodeRefs = (vNode) => {
733
- {
734
- vNode.$attrs$ && vNode.$attrs$.ref && vNode.$attrs$.ref(null);
735
- vNode.$children$ && vNode.$children$.map(nullifyVNodeRefs);
736
- }
737
- };
738
721
  var insertBefore = (parent, newNode, reference) => {
739
722
  {
740
723
  return parent == null ? void 0 : parent.insertBefore(newNode, reference);
@@ -1307,4 +1290,4 @@ exports.promiseResolve = promiseResolve;
1307
1290
  exports.registerInstance = registerInstance;
1308
1291
  exports.setNonce = setNonce;
1309
1292
 
1310
- //# sourceMappingURL=index-3826e5a2.js.map
1293
+ //# sourceMappingURL=index-550ac5f9.js.map