quikchat 1.0.2 → 1.0.4
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 +99 -49
- package/dist/quikchat.cjs.js +123 -54
- package/dist/quikchat.cjs.js.map +1 -1
- package/dist/quikchat.cjs.min.js +1 -1
- package/dist/quikchat.cjs.min.js.map +1 -1
- package/dist/quikchat.css +26 -17
- package/dist/quikchat.esm.js +123 -54
- package/dist/quikchat.esm.js.map +1 -1
- package/dist/quikchat.esm.min.js +1 -1
- package/dist/quikchat.esm.min.js.map +1 -1
- package/dist/quikchat.umd.js +123 -54
- package/dist/quikchat.umd.js.map +1 -1
- package/dist/quikchat.umd.min.js +1 -1
- package/dist/quikchat.umd.min.js.map +1 -1
- package/package.json +3 -2
package/dist/quikchat.cjs.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=Array(e);i<e;i++)n[i]=t[i];return n}function e(t,e){for(var i=0;i<e.length;i++){var
|
|
1
|
+
"use strict";function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var i=0,n=Array(e);i<e;i++)n[i]=t[i];return n}function e(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,a(n.key),n)}}function i(t,e,i){return(e=a(e))in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}function n(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,n)}return i}function r(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?n(Object(r),!0).forEach((function(e){i(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function s(e){return function(e){if(Array.isArray(e))return t(e)}(e)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(e)||function(e,i){if(e){if("string"==typeof e)return t(e,i);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,i):void 0}}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function a(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var n=i.call(t,e);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t,"string");return"symbol"==typeof e?e:e+""}var o=function(){return t=function t(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{theme:"quikchat-theme-light",onSend:function(){},trackHistory:!0,titleArea:{title:"Title Area",show:!1,align:"center"}};!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),"string"==typeof e&&(e=document.querySelector(e)),this._parentElement=e,this._theme=i.theme,this._onSend=i.onSend?i.onSend:function(){},this._createWidget(),i.titleArea&&(this.titleAreaSetContents(i.titleArea.title,i.titleArea.align),1==i.titleArea.show?this.titleAreaShow():this.titleAreaHide()),this._attachEventListeners(),this.trackHistory=i.trackHistory||!0,this._historyLimit=1e7,this._history=[]},i=[{key:"_createWidget",value:function(){var t='\n <div class="quikchat-base '.concat(this.theme,'">\n <div class="quikchat-title-area">\n <span style="font-size: 1.5em; font-weight: 600;">Title Area</span>\n </div>\n <div class="quikchat-messages-area"></div>\n <div class="quikchat-input-area">\n <textarea class="quikchat-input-textbox"></textarea>\n <button class="quikchat-input-send-btn">Send</button>\n </div>\n </div>\n ');this._parentElement.innerHTML=t,this._chatWidget=this._parentElement.querySelector(".quikchat-base"),this._titleArea=this._chatWidget.querySelector(".quikchat-title-area"),this._messagesArea=this._chatWidget.querySelector(".quikchat-messages-area"),this._inputArea=this._chatWidget.querySelector(".quikchat-input-area"),this._textEntry=this._inputArea.querySelector(".quikchat-input-textbox"),this._sendButton=this._inputArea.querySelector(".quikchat-input-send-btn"),this.msgid=0}},{key:"_attachEventListeners",value:function(){var t=this;this._sendButton.addEventListener("click",(function(){return t._onSend(t,t._textEntry.value.trim())})),window.addEventListener("resize",(function(){return t._handleContainerResize()})),this._chatWidget.addEventListener("resize",(function(){return t._handleContainerResize()})),this._textEntry.addEventListener("keydown",(function(e){e.shiftKey&&13===e.keyCode&&(e.preventDefault(),t._onSend(t,t._textEntry.value.trim()))}))}},{key:"setCallbackOnSend",value:function(t){this._onSend=t}},{key:"setCallbackonMessageAdded",value:function(t){this._onMessageAdded=t}},{key:"titleAreaToggle",value:function(){"none"===this._titleArea.style.display?this.titleAreaShow():this.titleAreaHide()}},{key:"titleAreaShow",value:function(){this._titleArea.style.display="",this._adjustMessagesAreaHeight()}},{key:"titleAreaHide",value:function(){this._titleArea.style.display="none",this._adjustMessagesAreaHeight()}},{key:"titleAreaSetContents",value:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"center";this._titleArea.innerHTML=t,this._titleArea.style.textAlign=e}},{key:"titleAreaGetContents",value:function(){return this._titleArea.innerHTML}},{key:"inputAreaToggle",value:function(){this._inputArea.classList.toggle("hidden"),"none"===this._inputArea.style.display?this.inputAreaShow():this.inputAreaHide()}},{key:"inputAreaShow",value:function(){this._inputArea.style.display="",this._adjustMessagesAreaHeight()}},{key:"inputAreaHide",value:function(){this._inputArea.style.display="none",this._adjustMessagesAreaHeight()}},{key:"_adjustMessagesAreaHeight",value:function(){var t=s(this._chatWidget.children).filter((function(t){return t.classList.contains("hidden")})).reduce((function(t,e){return t+e.offsetHeight}),0),e=this._chatWidget.offsetHeight;this._messagesArea.style.height="calc(100% - ".concat(e-t,"px)")}},{key:"_handleContainerResize",value:function(){this._adjustMessagesAreaHeight(),this._adjustSendButtonWidth()}},{key:"_adjustSendButtonWidth",value:function(){var t=this._sendButton.textContent.trim(),e=parseFloat(getComputedStyle(this._sendButton).fontSize)*t.length+16;this._sendButton.style.minWidth="".concat(e,"px")}},{key:"messageAddFull",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{content:"",userString:"user",align:"right",role:"user",userID:-1},e=this.msgid,i=document.createElement("div"),n="quikchat-msgid-"+String(e).padStart(10,"0");String(t.userString).padStart(10,"0"),i.classList.add("quikchat-message",n),this.msgid++,i.classList.add(this._messagesArea.children.length%2==1?"quikchat-message-1":"quikchat-message-2");var s=document.createElement("div");s.innerHTML=t.userString,s.style="width: 100%; text-align: ".concat(t.align,"; font-size: 1em; font-weight:700;");var a=document.createElement("div");a.style="width: 100%; text-align: ".concat(t.align,";"),a.innerHTML=t.content,i.appendChild(s),i.appendChild(a),this._messagesArea.appendChild(i),this._messagesArea.lastElementChild.scrollIntoView(),this._textEntry.value="",this._adjustMessagesAreaHeight();var o=(new Date).toISOString(),u=o;return this.trackHistory&&(this._history.push(r(r({msgid:e},t),{},{timestamp:o,updatedtime:u,messageDiv:i})),this._history.length>this._historyLimit&&this._history.shift()),this._onMessageAdded&&this._onMessageAdded(this,e),e}},{key:"messageAddNew",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"user",i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"right",n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"user";return this.messageAddFull({content:t,userString:e,align:i,role:n})}},{key:"messageRemove",value:function(t){var e=!1;try{this._messagesArea.removeChild(this._messagesArea.querySelector(".quikchat-msgid-".concat(String(t).padStart(10,"0")))),e=!0}catch(t){console.log("{String(n)} : Message ID not found")}return e&&this._history.splice(this._history.findIndex((function(e){return e.msgid===t})),1),e}},{key:"messageGetDOMObject",value:function(t){var e=null;try{e=this._messagesArea.querySelector(".quikchat-msgid-".concat(String(t).padStart(10,"0")))}catch(t){console.log("{String(n)} : Message ID not found")}return e}},{key:"messageGetContent",value:function(t){var e="";try{e=this._history.filter((function(e){return e.msgid===t}))[0].content}catch(t){console.log("{String(n)} : Message ID not found")}return e}},{key:"messageAppendContent",value:function(t,e){try{this._messagesArea.querySelector(".quikchat-msgid-".concat(String(t).padStart(10,"0"))).lastChild.innerHTML+=e;var i=this._history.filter((function(e){return e.msgid===t}))[0];i.content+=e,i.updatedtime=(new Date).toISOString(),this._messagesArea.lastElementChild.scrollIntoView()}catch(t){console.log("{String(n)} : Message ID not found")}}},{key:"messageReplaceContent",value:function(t,e){var i=!1;try{this._messagesArea.querySelector(".quikchat-msgid-".concat(String(t).padStart(10,"0"))).lastChild.innerHTML=e,this._history.filter((function(e){return e.msgid===t}))[0].content=e,i=!0}catch(t){console.log("{String(n)} : Message ID not found")}return i}},{key:"historyGet",value:function(t,e){return null==t&&(t=0,e=this._history.length),void 0===e&&(e=t<0?e:t+1),this._history.slice(t,e)}},{key:"historyClear",value:function(){this.msgid=0,this._history=[]}},{key:"historyGetLength",value:function(){return this._history.length}},{key:"historyGetMessage",value:function(t){return t>=0&&t<this._history.length&&this._history[t],{}}},{key:"historyGetMessageContent",value:function(t){return this._history[t].message}},{key:"changeTheme",value:function(t){this._chatWidget.classList.remove(this._theme),this._chatWidget.classList.add(t),this._theme=t}},{key:"theme",get:function(){return this._theme}}],n=[{key:"version",value:function(){return{version:"1.0.4",license:"BSD-2",url:"https://github/deftio/quikchat"}}}],i&&e(t.prototype,i),n&&e(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,i,n}();module.exports=o;
|
|
2
2
|
//# sourceMappingURL=quikchat.cjs.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quikchat.cjs.min.js","sources":["../src/quikchat.js"],"sourcesContent":["\nclass quikchat {\n /**\n * \n * @param string or DOM element parentElement \n * @param {*} meta \n */\n constructor(parentElement, \n meta = { \n theme: 'quikchat-theme-light', \n onSend: () => { },\n trackHistory: true,\n }) {\n if (typeof parentElement === 'string') {\n parentElement = document.querySelector(parentElement);\n }\n this._parentElement = parentElement;\n this._theme = meta.theme;\n this._onSend = meta.onSend ? meta.onSend : () => { };\n this._createWidget();\n // title area\n if (meta.titleArea) {\n this.titleAreaSetContents(meta.titleArea.title, meta.titleArea.align);\n if (meta.titleArea.show) {\n this.titleAreaShow();\n } else {\n this.titleAreaHide();\n }\n }\n this._attachEventListeners();\n this.trackHistory = meta.trackHistory || true;\n this._history = [];\n }\n\n _createWidget() {\n const widgetHTML =\n `\n <div class=\"quikchat-base ${this.theme}\">\n <div class=\"quikchat-title-area\">\n <span style=\"font-size: 1.5em; font-weight: 600;\">Title Area</span>\n </div>\n <div class=\"quikchat-messages-area\"></div>\n <div class=\"quikchat-input-area\">\n <textarea class=\"quikchat-input-textbox\"></textarea>\n <button class=\"quikchat-input-send-btn\">Send</button>\n </div>\n </div>\n `;\n\n this._parentElement.innerHTML = widgetHTML;\n this._chatWidget = this._parentElement.querySelector('.quikchat-base');\n this._titleArea = this._chatWidget.querySelector('.quikchat-title-area');\n this._messagesArea = this._chatWidget.querySelector('.quikchat-messages-area');\n this._inputArea = this._chatWidget.querySelector('.quikchat-input-area');\n this._textEntry = this._inputArea.querySelector('.quikchat-input-textbox');\n this._sendButton = this._inputArea.querySelector('.quikchat-input-send-btn');\n this.msgid = 0;\n }\n $() {\n }\n _attachEventListeners() {\n this._sendButton.addEventListener('click', () => this._onSend(this, this._textEntry.value.trim()));\n window.addEventListener('resize', () => this._handleContainerResize());\n this._chatWidget.addEventListener('resize', () => this._handleContainerResize());\n this._textEntry.addEventListener('keydown', (event) => {\n // Check if Shift + Enter is pressed\n if (event.shiftKey && event.keyCode === 13) {\n // Prevent default behavior (adding new line)\n event.preventDefault();\n this._onSend(this, this._textEntry.value.trim())\n }\n });\n }\n\n titleAreaToggle() {\n this._titleArea.style.display === 'none' ? this.titleAreaShow() : this.titleAreaHide();\n }\n\n titleAreaShow() {\n this._titleArea.style.display = '';\n this._adjustMessagesAreaHeight();\n }\n\n titleAreaHide() {\n this._titleArea.style.display = 'none';\n this._adjustMessagesAreaHeight();\n }\n\n titleAreaSetContents(title, align = 'center') {\n this._titleArea.innerHTML = title;\n this._titleArea.style.textAlign = align;\n }\n\n titleAreaGetContents() {\n return this._titleArea.innerHTML;\n }\n\n inputAreaToggle() {\n this._inputArea.classList.toggle('hidden');\n this._inputArea.style.display === 'none' ? this.inputAreaShow() : this.inputAreaHide();\n }\n\n inputAreaShow() {\n this._inputArea.style.display = '';\n this._adjustMessagesAreaHeight();\n }\n\n inputAreaHide() {\n this._inputArea.style.display = 'none';\n this._adjustMessagesAreaHeight();\n }\n\n _adjustMessagesAreaHeight() {\n const hiddenElements = [...this._chatWidget.children].filter(child => child.classList.contains('hidden'));\n const totalHiddenHeight = hiddenElements.reduce((sum, child) => sum + child.offsetHeight, 0);\n const containerHeight = this._chatWidget.offsetHeight;\n this._messagesArea.style.height = `calc(100% - ${containerHeight - totalHiddenHeight}px)`;\n }\n\n _handleContainerResize() {\n this._adjustMessagesAreaHeight();\n this._adjustSendButtonWidth();\n //console.log('Container resized');\n }\n\n _adjustSendButtonWidth() {\n const sendButtonText = this._sendButton.textContent.trim();\n const fontSize = parseFloat(getComputedStyle(this._sendButton).fontSize);\n const minWidth = fontSize * sendButtonText.length + 16;\n this._sendButton.style.minWidth = `${minWidth}px`;\n }\n\n messageAddNew(message, userObject = \"test\", align = 'left') {\n const messageDiv = document.createElement('div');\n const msgid = this.msgid;\n const msgidClass = 'quikchat-msgid-' + String(msgid).padStart(10, '0');\n messageDiv.classList.add('quikchat-message', msgidClass);\n this.msgid++;\n messageDiv.classList.add(this._messagesArea.children.length % 2 === 1 ? 'quikchat-message-1' : 'quikchat-message-2');\n let user = {name: \"not-set\",role : \"user\"};\n if (typeof userObject === 'object') {\n for (const key in userObject) {\n user[key] = userObject[key];\n }\n }\n else { // if userObject is a string\n user[\"name\"] = userObject ;\n }\n const userDiv = document.createElement('div');\n userDiv.innerHTML = user.name;\n userDiv.style = `width: 100%; text-align: ${align}; font-size: 1em; font-weight:700; color: #444;`;\n\n const contentDiv = document.createElement('div');\n contentDiv.style = `width: 100%; text-align: ${align};`;\n contentDiv.innerHTML = message;\n\n messageDiv.appendChild(userDiv);\n messageDiv.appendChild(contentDiv);\n this._messagesArea.appendChild(messageDiv);\n this._messagesArea.lastChild.scrollIntoView();\n\n this._textEntry.value = '';\n this._adjustMessagesAreaHeight();\n const timestamp = new Date().toISOString();\n const updatedtime = timestamp;\n if (this.trackHistory) {\n this._history.push({ msgid, user, message, align, timestamp, updatedtime, messageDiv});\n if (this._history.length > 10000000) {\n this._history.shift();\n }\n }\n return {msgid};\n }\n\n messageRemove(n) {\n // use css selector to remove the message\n let sucess = false;\n try {\n this._messagesArea.removeChild(this._messagesArea.querySelector(`.quikchat-msgid-${String(n).padStart(10, '0')}`));\n sucess = true;\n }\n catch (error) {\n console.log(`{String(n)} : Message ID not found`);\n }\n if (sucess) {\n // remove from history\n this._history = this._history.filter((item) => item.msgid !== n);\n }\n return sucess;\n }\n /* returns the message html object from the DOM\n */\n messageGetDOMObject(n) {\n let msg = null;\n // now use css selector to get the message \n try {\n msg = this._messagesArea.querySelector(`.quikchat-msgid-${String(n).padStart(10, '0')}`);\n } \n catch (error) \n {\n console.log(`{String(n)} : Message ID not found`);\n }\n return msg; \n }\n /* returns the message content only\n */\n messageGetContent(n) {\n let content = \"\"\n // now use css selector to get the message \n try {\n content = this._messagesArea.querySelector(`.quikchat-msgid-${String(n).padStart(10, '0')}`).lastChild.textContent;\n } \n catch (error) \n {\n console.log(`{String(n)} : Message ID not found`);\n }\n return content; \n }\n\n /* append message to the message content\n */\n messageAppendContent(n, content) {\n let sucess = false;\n try {\n this._messagesArea.querySelector(`.quikchat-msgid-${String(n).padStart(10, '0')}`).lastChild.innerHTML += content;\n sucess = true;\n } \n catch (error) \n {\n console.log(`{String(n)} : Message ID not found`);\n } \n }\n /* replace message content\n */\n messageReplaceContent(n, content) {\n let sucess = false;\n try {\n this._messagesArea.querySelector(`.quikchat-msgid-${String(n).padStart(10, '0')}`).lastChild.innerHTML = content;\n sucess = true;\n } \n catch (error) \n {\n console.log(`{String(n)} : Message ID not found`);\n }\n return sucess;\n }\n // history functions\n /**\n * \n * @param {*} n \n * @param {*} m \n * @returns array of history messages\n */\n historyGet(n,m) {\n\n if (n == undefined) {\n n = 0;\n m= this._history.length;\n }\n if (m === undefined) {\n m = n < 0 ? m: n + 1;\n }\n return this._history.slice(n,m);\n }\n\n historyClear() {\n this.msgid = 0;\n this._history = [];\n } \n\n historyGetLength() {\n return this._history.length;\n } \n\n historyGetMessage(n) {\n if ( n>=0 && n < this._history.length) {\n this._history[n];\n }\n return {};\n\n } \n\n historyGetMessageContent(n) {\n return this._history[n].message;\n }\n\n\n changeTheme(newTheme) {\n this._chatWidget.classList.remove(this._theme);\n this._chatWidget.classList.add(newTheme);\n this._theme = newTheme;\n }\n\n get theme() {\n return this._theme;\n }\n\n static getVersion() {\n return {\"version\" : \"1.0.2\"}\n }\n}\n\nexport default quikchat;\n"],"names":["quikchat","parentElement","meta","arguments","length","undefined","theme","onSend","trackHistory","_classCallCheck","document","querySelector","this","_parentElement","_theme","_onSend","_createWidget","titleArea","titleAreaSetContents","title","align","show","titleAreaShow","titleAreaHide","_attachEventListeners","_history","key","value","widgetHTML","concat","innerHTML","_chatWidget","_titleArea","_messagesArea","_inputArea","_textEntry","_sendButton","msgid","_this","addEventListener","trim","window","_handleContainerResize","event","shiftKey","keyCode","preventDefault","style","display","_adjustMessagesAreaHeight","textAlign","classList","toggle","inputAreaShow","inputAreaHide","totalHiddenHeight","_toConsumableArray","children","filter","child","contains","reduce","sum","offsetHeight","containerHeight","height","_adjustSendButtonWidth","sendButtonText","textContent","minWidth","parseFloat","getComputedStyle","fontSize","message","userObject","messageDiv","createElement","msgidClass","String","padStart","add","user","name","role","_typeof","userDiv","contentDiv","appendChild","lastChild","scrollIntoView","timestamp","Date","toISOString","updatedtime","push","shift","n","sucess","removeChild","error","console","log","item","msg","content","m","slice","newTheme","remove","get","version"],"mappings":"i6CACMA,EAAQ,WA+BT,SAzBD,SAAAA,EAAYC,GAKL,IAJHC,EAAIC,UAAAC,OAAAD,QAAAE,IAAAF,UAAAE,GAAAF,UAAG,GAAA,CACHG,MAAO,uBACPC,OAAQ,WAAS,EACjBC,cAAc,gGACjBC,MAAAT,GAC4B,iBAAlBC,IACPA,EAAgBS,SAASC,cAAcV,IAE3CW,KAAKC,eAAiBZ,EACtBW,KAAKE,OAASZ,EAAKI,MACnBM,KAAKG,QAAUb,EAAKK,OAASL,EAAKK,OAAS,aAC3CK,KAAKI,gBAEDd,EAAKe,YACLL,KAAKM,qBAAqBhB,EAAKe,UAAUE,MAAOjB,EAAKe,UAAUG,OAC3DlB,EAAKe,UAAUI,KACfT,KAAKU,gBAELV,KAAKW,iBAGbX,KAAKY,wBACLZ,KAAKJ,aAAeN,EAAKM,eAAgB,EACzCI,KAAKa,SAAW,EACpB,IAAC,CAAA,CAAAC,IAAA,gBAAAC,MAED,WACI,IAAMC,EAAUC,2CAAAA,OAEgBjB,KAAKN,MAUhC,weAELM,KAAKC,eAAeiB,UAAYF,EAChChB,KAAKmB,YAAcnB,KAAKC,eAAeF,cAAc,kBACrDC,KAAKoB,WAAapB,KAAKmB,YAAYpB,cAAc,wBACjDC,KAAKqB,cAAgBrB,KAAKmB,YAAYpB,cAAc,2BACpDC,KAAKsB,WAAatB,KAAKmB,YAAYpB,cAAc,wBACjDC,KAAKuB,WAAavB,KAAKsB,WAAWvB,cAAc,2BAChDC,KAAKwB,YAAcxB,KAAKsB,WAAWvB,cAAc,4BACjDC,KAAKyB,MAAQ,CACjB,GAAC,CAAAX,IAAA,IAAAC,MACD,WACA,GAAC,CAAAD,IAAA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yBqE,GACrB,OAAOpF,KAAKa,SAASuE,GAAGvB,OAC5B,GAAC,CAAA/C,IAAA,cAAAC,MAGD,SAAYgF,GACR/F,KAAKmB,YAAYoB,UAAUyD,OAAOhG,KAAKE,QACvCF,KAAKmB,YAAYoB,UAAU6B,IAAI2B,GAC/B/F,KAAKE,OAAS6F,CAClB,GAAC,CAAAjF,IAAA,QAAAmF,IAED,WACI,OAAOjG,KAAKE,MAChB,MAAC,CAAA,CAAAY,IAAA,aAAAC,MAED,WACI,MAAO,CAACmF,QAAY,QACxB,gGAAC,CA1SS"}
|
|
1
|
+
{"version":3,"file":"quikchat.cjs.min.js","sources":["../src/quikchat.js"],"sourcesContent":["\nclass quikchat {\n /**\n * \n * @param string or DOM element parentElement \n * @param {*} meta \n */\n constructor(parentElement, \n meta = { \n theme: 'quikchat-theme-light', \n onSend: () => { }, \n trackHistory: true,\n titleArea: {title: \"Title Area\", show: false, align: \"center\"}\n }) \n {\n if (typeof parentElement === 'string') {\n parentElement = document.querySelector(parentElement);\n }\n this._parentElement = parentElement;\n this._theme = meta.theme;\n this._onSend = meta.onSend ? meta.onSend : () => { };\n this._createWidget();\n // title area\n if (meta.titleArea) {\n this.titleAreaSetContents(meta.titleArea.title, meta.titleArea.align);\n if (meta.titleArea.show == true) {\n this.titleAreaShow();\n } else {\n this.titleAreaHide();\n }\n }\n this._attachEventListeners();\n this.trackHistory = meta.trackHistory || true;\n this._historyLimit = 10000000;\n this._history = [];\n }\n\n _createWidget() {\n const widgetHTML =\n `\n <div class=\"quikchat-base ${this.theme}\">\n <div class=\"quikchat-title-area\">\n <span style=\"font-size: 1.5em; font-weight: 600;\">Title Area</span>\n </div>\n <div class=\"quikchat-messages-area\"></div>\n <div class=\"quikchat-input-area\">\n <textarea class=\"quikchat-input-textbox\"></textarea>\n <button class=\"quikchat-input-send-btn\">Send</button>\n </div>\n </div>\n `;\n\n this._parentElement.innerHTML = widgetHTML;\n this._chatWidget = this._parentElement.querySelector('.quikchat-base');\n this._titleArea = this._chatWidget.querySelector('.quikchat-title-area');\n this._messagesArea = this._chatWidget.querySelector('.quikchat-messages-area');\n this._inputArea = this._chatWidget.querySelector('.quikchat-input-area');\n this._textEntry = this._inputArea.querySelector('.quikchat-input-textbox');\n this._sendButton = this._inputArea.querySelector('.quikchat-input-send-btn');\n this.msgid = 0;\n }\n\n _attachEventListeners() {\n this._sendButton.addEventListener('click', () => this._onSend(this, this._textEntry.value.trim()));\n window.addEventListener('resize', () => this._handleContainerResize());\n this._chatWidget.addEventListener('resize', () => this._handleContainerResize());\n this._textEntry.addEventListener('keydown', (event) => {\n // Check if Shift + Enter is pressed\n if (event.shiftKey && event.keyCode === 13) {\n // Prevent default behavior (adding new line)\n event.preventDefault();\n this._onSend(this, this._textEntry.value.trim())\n }\n });\n }\n // set the onSend function callback.\n setCallbackOnSend(callback) {\n this._onSend = callback;\n }\n // set a callback for everytime a message is added (listener)\n setCallbackonMessageAdded(callback) {\n this._onMessageAdded = callback;\n }\n\n // Public methods\n titleAreaToggle() {\n this._titleArea.style.display === 'none' ? this.titleAreaShow() : this.titleAreaHide();\n }\n\n titleAreaShow() {\n this._titleArea.style.display = '';\n this._adjustMessagesAreaHeight();\n }\n\n titleAreaHide() {\n this._titleArea.style.display = 'none';\n this._adjustMessagesAreaHeight();\n }\n\n titleAreaSetContents(title, align = 'center') {\n this._titleArea.innerHTML = title;\n this._titleArea.style.textAlign = align;\n }\n\n titleAreaGetContents() {\n return this._titleArea.innerHTML;\n }\n\n inputAreaToggle() {\n this._inputArea.classList.toggle('hidden');\n this._inputArea.style.display === 'none' ? this.inputAreaShow() : this.inputAreaHide();\n }\n\n inputAreaShow() {\n this._inputArea.style.display = '';\n this._adjustMessagesAreaHeight();\n }\n\n inputAreaHide() {\n this._inputArea.style.display = 'none';\n this._adjustMessagesAreaHeight();\n }\n\n _adjustMessagesAreaHeight() {\n const hiddenElements = [...this._chatWidget.children].filter(child => child.classList.contains('hidden'));\n const totalHiddenHeight = hiddenElements.reduce((sum, child) => sum + child.offsetHeight, 0);\n const containerHeight = this._chatWidget.offsetHeight;\n this._messagesArea.style.height = `calc(100% - ${containerHeight - totalHiddenHeight}px)`;\n }\n\n _handleContainerResize() {\n this._adjustMessagesAreaHeight();\n this._adjustSendButtonWidth();\n //console.log('Container resized');\n }\n\n _adjustSendButtonWidth() {\n const sendButtonText = this._sendButton.textContent.trim();\n const fontSize = parseFloat(getComputedStyle(this._sendButton).fontSize);\n const minWidth = fontSize * sendButtonText.length + 16;\n this._sendButton.style.minWidth = `${minWidth}px`;\n }\n \n messageAddFull(input = {content: \"\", userString: \"user\", align : \"right\", role : \"user\", userID : -1}) {\n const msgid = this.msgid;\n const messageDiv = document.createElement('div');\n const msgidClass = 'quikchat-msgid-' + String(msgid).padStart(10, '0');\n const userIdClass = 'quikchat-userid-' + String(input.userString).padStart(10, '0'); // hash this..\n messageDiv.classList.add('quikchat-message', msgidClass);\n this.msgid++;\n messageDiv.classList.add(this._messagesArea.children.length % 2 === 1 ? 'quikchat-message-1' : 'quikchat-message-2');\n \n const userDiv = document.createElement('div');\n userDiv.innerHTML = input.userString;\n userDiv.style = `width: 100%; text-align: ${input.align}; font-size: 1em; font-weight:700;`;\n\n const contentDiv = document.createElement('div');\n contentDiv.style = `width: 100%; text-align: ${input.align};`;\n contentDiv.innerHTML = input.content;\n\n messageDiv.appendChild(userDiv);\n messageDiv.appendChild(contentDiv);\n this._messagesArea.appendChild(messageDiv);\n //this._messagesArea.lastChild.scrollIntoView();\n this._messagesArea.lastElementChild.scrollIntoView()\n\n this._textEntry.value = '';\n this._adjustMessagesAreaHeight();\n const timestamp = new Date().toISOString();\n const updatedtime = timestamp;\n if (this.trackHistory) {\n this._history.push({ msgid, ...input, timestamp, updatedtime, messageDiv});\n if (this._history.length > this._historyLimit) {\n this._history.shift();\n }\n }\n if (this._onMessageAdded) {\n this._onMessageAdded(this, msgid);\n };\n return msgid;\n }\n messageAddNew(content=\"\", userString=\"user\", align = \"right\", role = \"user\") {\n return this.messageAddFull( \n {content: content, userString: userString, align: align, role: role}\n );\n }\n messageRemove(n) {\n // use css selector to remove the message\n let sucess = false;\n try {\n this._messagesArea.removeChild(this._messagesArea.querySelector(`.quikchat-msgid-${String(n).padStart(10, '0')}`));\n sucess = true;\n }\n catch (error) {\n console.log(`{String(n)} : Message ID not found`);\n }\n if (sucess) {\n // slow way to remove from history\n //this._history = this._history.filter((item) => item.msgid !== n); // todo make this more efficient\n\n // better way to delete this from history\n this._history.splice(this._history.findIndex((item) => item.msgid === n), 1);\n }\n return sucess;\n }\n /* returns the message html object from the DOM\n */\n messageGetDOMObject(n) {\n let msg = null;\n // now use css selector to get the message \n try {\n msg = this._messagesArea.querySelector(`.quikchat-msgid-${String(n).padStart(10, '0')}`);\n } \n catch (error) \n {\n console.log(`{String(n)} : Message ID not found`);\n }\n return msg; \n }\n /* returns the message content only\n */\n messageGetContent(n) {\n let content = \"\"\n // now use css selector to get the message \n try {\n // get from history..\n content = this._history.filter((item) => item.msgid === n)[0].content;\n //content = this._messagesArea.querySelector(`.quikchat-msgid-${String(n).padStart(10, '0')}`).lastChild.textContent;\n } \n catch (error) \n {\n console.log(`{String(n)} : Message ID not found`);\n }\n return content; \n }\n\n /* append message to the message content\n */\n messageAppendContent(n, content) {\n let sucess = false;\n try {\n this._messagesArea.querySelector(`.quikchat-msgid-${String(n).padStart(10, '0')}`).lastChild.innerHTML += content;\n // update history\n let item = this._history.filter((item) => item.msgid === n)[0];\n item.content += content;\n item.updatedtime = new Date().toISOString();\n sucess = true;\n //this._messagesArea.lastChild.scrollIntoView();\n this._messagesArea.lastElementChild.scrollIntoView()\n } \n catch (error) \n {\n console.log(`{String(n)} : Message ID not found`);\n } \n }\n /* replace message content\n */\n messageReplaceContent(n, content) {\n let sucess = false;\n try {\n this._messagesArea.querySelector(`.quikchat-msgid-${String(n).padStart(10, '0')}`).lastChild.innerHTML = content;\n // update history\n this._history.filter((item) => item.msgid === n)[0].content = content;\n sucess = true;\n } \n catch (error) \n {\n console.log(`{String(n)} : Message ID not found`);\n }\n return sucess;\n }\n // history functions\n /**\n * \n * @param {*} n \n * @param {*} m \n * @returns array of history messages\n */\n historyGet(n,m) {\n\n if (n == undefined) {\n n = 0;\n m= this._history.length;\n }\n if (m === undefined) {\n m = n < 0 ? m: n + 1;\n }\n // remember that entries could be deleted. TODO: So we need to return the actual history entries\n // so now we need to find the array index that correspondes to messageIds n (start) and m (end)\n \n return this._history.slice(n,m);\n }\n\n historyClear() {\n this.msgid = 0;\n this._history = [];\n } \n\n historyGetLength() {\n return this._history.length;\n } \n\n historyGetMessage(n) {\n if ( n>=0 && n < this._history.length) {\n this._history[n];\n }\n return {};\n\n } \n\n historyGetMessageContent(n) {\n return this._history[n].message;\n }\n\n\n changeTheme(newTheme) {\n this._chatWidget.classList.remove(this._theme);\n this._chatWidget.classList.add(newTheme);\n this._theme = newTheme;\n }\n\n get theme() {\n return this._theme;\n }\n\n static version() {\n return {\"version\" : \"1.0.4\", \"license\" : \"BSD-2\", \"url\" :\"https://github/deftio/quikchat\"};\n }\n}\n\nexport default quikchat;\n"],"names":["quikchat","parentElement","meta","arguments","length","undefined","theme","onSend","trackHistory","titleArea","title","show","align","_classCallCheck","document","querySelector","this","_parentElement","_theme","_onSend","_createWidget","titleAreaSetContents","titleAreaShow","titleAreaHide","_attachEventListeners","_historyLimit","_history","key","value","widgetHTML","concat","innerHTML","_chatWidget","_titleArea","_messagesArea","_inputArea","_textEntry","_sendButton","msgid","_this","addEventListener","trim","window","_handleContainerResize","event","shiftKey","keyCode","preventDefault","callback","_onMessageAdded","style","display","_adjustMessagesAreaHeight","textAlign","classList","toggle","inputAreaShow","inputAreaHide","totalHiddenHeight","_toConsumableArray","children","filter","child","contains","reduce","sum","offsetHeight","containerHeight","height","_adjustSendButtonWidth","sendButtonText","textContent","minWidth","parseFloat","getComputedStyle","fontSize","input","content","userString","role","userID","messageDiv","createElement","msgidClass","String","padStart","add","userDiv","contentDiv","appendChild","lastElementChild","scrollIntoView","timestamp","Date","toISOString","updatedtime","push","_objectSpread","shift","messageAddFull","n","sucess","removeChild","error","console","log","splice","findIndex","item","msg","lastChild","m","slice","message","newTheme","remove","get","version","license","url"],"mappings":"u3DACMA,EAAQ,WAkCT,SA5BD,SAAAA,EAAYC,GAOR,IANIC,EAAIC,UAAAC,OAAAD,QAAAE,IAAAF,UAAAE,GAAAF,UAAG,GAAA,CACHG,MAAO,uBACPC,OAAQ,WAAS,EACjBC,cAAc,EACdC,UAAW,CAACC,MAAO,aAAcC,MAAM,EAAOC,MAAO,wGACxDC,MAAAb,GAEwB,iBAAlBC,IACPA,EAAgBa,SAASC,cAAcd,IAE3Ce,KAAKC,eAAiBhB,EACtBe,KAAKE,OAAShB,EAAKI,MACnBU,KAAKG,QAAUjB,EAAKK,OAASL,EAAKK,OAAS,aAC3CS,KAAKI,gBAEDlB,EAAKO,YACLO,KAAKK,qBAAqBnB,EAAKO,UAAUC,MAAOR,EAAKO,UAAUG,OACpC,GAAvBV,EAAKO,UAAUE,KACfK,KAAKM,gBAELN,KAAKO,iBAGbP,KAAKQ,wBACLR,KAAKR,aAAeN,EAAKM,eAAgB,EACzCQ,KAAKS,cAAgB,IACrBT,KAAKU,SAAW,EACpB,IAAC,CAAA,CAAAC,IAAA,gBAAAC,MAED,WACI,IAAMC,EAAUC,2CAAAA,OAEgBd,KAAKV,MAUhC,weAELU,KAAKC,eAAec,UAAYF,EAChCb,KAAKgB,YAAchB,KAAKC,eAAeF,cAAc,kBACrDC,KAAKiB,WAAajB,KAAKgB,YAAYjB,cAAc,wBACjDC,KAAKkB,cAAgBlB,KAAKgB,YAAYjB,cAAc,2BACpDC,KAAKmB,WAAanB,KAAKgB,YAAYjB,cAAc,wBACjDC,KAAKoB,WAAapB,KAAKmB,WAAWpB,cAAc,2BAChDC,KAAKqB,YAAcrB,KAAKmB,WAAWpB,cAAc,4BACjDC,KAAKsB,MAAQ,CACjB,GAAC,CAAAX,IAAA,wBAAAC,MAED,WAAwB,IAAAW,EA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-
/*
|
|
1
|
+
/*
|
|
2
|
+
quikchat.css see www.github.com/deftio/quikchat for more info
|
|
3
|
+
|
|
4
|
+
Base Styles - Affect behavior so change with char
|
|
5
|
+
For Themes scroll past this section
|
|
6
|
+
*/
|
|
7
|
+
|
|
2
8
|
.quikchat-base {
|
|
3
9
|
display: flex;
|
|
4
10
|
flex-direction: column;
|
|
@@ -6,6 +12,7 @@
|
|
|
6
12
|
width: 100%;
|
|
7
13
|
min-width: 200px;
|
|
8
14
|
min-height: 200px;
|
|
15
|
+
box-sizing: border-box !important;
|
|
9
16
|
}
|
|
10
17
|
|
|
11
18
|
.quikchat-title-area {
|
|
@@ -22,13 +29,15 @@
|
|
|
22
29
|
flex-grow: 1;
|
|
23
30
|
padding: 8px;
|
|
24
31
|
overflow-y: auto;
|
|
32
|
+
border-radius: 1rem;
|
|
25
33
|
width: 100%;
|
|
26
34
|
}
|
|
27
35
|
|
|
28
36
|
.quikchat-message {
|
|
29
|
-
padding:
|
|
37
|
+
padding: 4px;
|
|
30
38
|
white-space: pre-wrap;
|
|
31
39
|
word-wrap: break-word;
|
|
40
|
+
border-radius: 4px;
|
|
32
41
|
}
|
|
33
42
|
|
|
34
43
|
.quikchat-input-area {
|
|
@@ -38,26 +47,30 @@
|
|
|
38
47
|
min-height: 56px;
|
|
39
48
|
height: 4em;
|
|
40
49
|
width: 100%;
|
|
41
|
-
|
|
50
|
+
box-sizing: border-box !important;
|
|
42
51
|
|
|
52
|
+
}
|
|
53
|
+
|
|
43
54
|
.quikchat-input-textbox {
|
|
44
55
|
flex-grow: 1;
|
|
45
56
|
min-height: 40px;
|
|
46
57
|
resize: none;
|
|
47
|
-
padding:
|
|
58
|
+
padding: 4px;
|
|
59
|
+
height: 100%;
|
|
48
60
|
}
|
|
49
61
|
|
|
50
62
|
.quikchat-input-send-btn {
|
|
51
63
|
margin-left: 8px;
|
|
52
|
-
padding: 8px
|
|
64
|
+
padding: 8px;
|
|
53
65
|
height: 100%;
|
|
66
|
+
min-width: 5rem;
|
|
54
67
|
cursor: pointer;
|
|
55
68
|
white-space: nowrap;
|
|
56
69
|
}
|
|
57
|
-
|
|
70
|
+
|
|
58
71
|
/* ***************************************** */
|
|
59
|
-
/*
|
|
60
|
-
This theme is for debugging purposes
|
|
72
|
+
/* quikchat theme debug
|
|
73
|
+
This theme is for debugging purposes and has a very distinct look.
|
|
61
74
|
*/
|
|
62
75
|
.quikchat-theme-debug {
|
|
63
76
|
border: 1px solid black;
|
|
@@ -109,12 +122,13 @@
|
|
|
109
122
|
}
|
|
110
123
|
|
|
111
124
|
/* ********************************** */
|
|
112
|
-
/* theme dark
|
|
125
|
+
/* quikchat theme dark */
|
|
113
126
|
.quikchat-theme-dark {
|
|
114
127
|
border: 1px solid #555555;
|
|
115
128
|
border-radius: 8px;
|
|
116
129
|
background-color: #212121;
|
|
117
130
|
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
|
|
131
|
+
color: #eceff1;
|
|
118
132
|
}
|
|
119
133
|
|
|
120
134
|
.quikchat-theme-dark .quikchat-title-area {
|
|
@@ -128,21 +142,16 @@
|
|
|
128
142
|
.quikchat-theme-dark .quikchat-messages-area {
|
|
129
143
|
background-color: #212121;
|
|
130
144
|
color: #eceff1;
|
|
131
|
-
padding: 10px;
|
|
132
145
|
}
|
|
133
146
|
|
|
134
147
|
.quikchat-theme-dark .quikchat-message-1 {
|
|
135
148
|
background-color: #404040e5;
|
|
136
|
-
|
|
137
|
-
border-radius: 4px;
|
|
138
|
-
margin-bottom: 4px;
|
|
149
|
+
color: #eceff1;
|
|
139
150
|
}
|
|
140
151
|
|
|
141
152
|
.quikchat-theme-dark .quikchat-message-2 {
|
|
142
153
|
background-color: #5a5a5a;
|
|
143
|
-
|
|
144
|
-
border-radius: 4px;
|
|
145
|
-
margin-bottom: 4px;
|
|
154
|
+
color: #fbfbfb;
|
|
146
155
|
}
|
|
147
156
|
|
|
148
157
|
.quikchat-theme-dark .quikchat-input-area {
|
|
@@ -174,7 +183,7 @@
|
|
|
174
183
|
}
|
|
175
184
|
|
|
176
185
|
/* ********************************** */
|
|
177
|
-
/* theme light */
|
|
186
|
+
/* quikchat theme light */
|
|
178
187
|
|
|
179
188
|
.quikchat-theme-light {
|
|
180
189
|
border: 1px solid #cccccc;
|
package/dist/quikchat.esm.js
CHANGED
|
@@ -20,12 +20,41 @@ function _createClass(e, r, t) {
|
|
|
20
20
|
writable: !1
|
|
21
21
|
}), e;
|
|
22
22
|
}
|
|
23
|
+
function _defineProperty(e, r, t) {
|
|
24
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
25
|
+
value: t,
|
|
26
|
+
enumerable: !0,
|
|
27
|
+
configurable: !0,
|
|
28
|
+
writable: !0
|
|
29
|
+
}) : e[r] = t, e;
|
|
30
|
+
}
|
|
23
31
|
function _iterableToArray(r) {
|
|
24
32
|
if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
|
|
25
33
|
}
|
|
26
34
|
function _nonIterableSpread() {
|
|
27
35
|
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
28
36
|
}
|
|
37
|
+
function ownKeys(e, r) {
|
|
38
|
+
var t = Object.keys(e);
|
|
39
|
+
if (Object.getOwnPropertySymbols) {
|
|
40
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
41
|
+
r && (o = o.filter(function (r) {
|
|
42
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
43
|
+
})), t.push.apply(t, o);
|
|
44
|
+
}
|
|
45
|
+
return t;
|
|
46
|
+
}
|
|
47
|
+
function _objectSpread2(e) {
|
|
48
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
49
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
50
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
51
|
+
_defineProperty(e, r, t[r]);
|
|
52
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
53
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return e;
|
|
57
|
+
}
|
|
29
58
|
function _toConsumableArray(r) {
|
|
30
59
|
return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
|
|
31
60
|
}
|
|
@@ -43,15 +72,6 @@ function _toPropertyKey(t) {
|
|
|
43
72
|
var i = _toPrimitive(t, "string");
|
|
44
73
|
return "symbol" == typeof i ? i : i + "";
|
|
45
74
|
}
|
|
46
|
-
function _typeof(o) {
|
|
47
|
-
"@babel/helpers - typeof";
|
|
48
|
-
|
|
49
|
-
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
|
|
50
|
-
return typeof o;
|
|
51
|
-
} : function (o) {
|
|
52
|
-
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
53
|
-
}, _typeof(o);
|
|
54
|
-
}
|
|
55
75
|
function _unsupportedIterableToArray(r, a) {
|
|
56
76
|
if (r) {
|
|
57
77
|
if ("string" == typeof r) return _arrayLikeToArray(r, a);
|
|
@@ -70,7 +90,12 @@ var quikchat = /*#__PURE__*/function () {
|
|
|
70
90
|
var meta = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
71
91
|
theme: 'quikchat-theme-light',
|
|
72
92
|
onSend: function onSend() {},
|
|
73
|
-
trackHistory: true
|
|
93
|
+
trackHistory: true,
|
|
94
|
+
titleArea: {
|
|
95
|
+
title: "Title Area",
|
|
96
|
+
show: false,
|
|
97
|
+
align: "center"
|
|
98
|
+
}
|
|
74
99
|
};
|
|
75
100
|
_classCallCheck(this, quikchat);
|
|
76
101
|
if (typeof parentElement === 'string') {
|
|
@@ -83,7 +108,7 @@ var quikchat = /*#__PURE__*/function () {
|
|
|
83
108
|
// title area
|
|
84
109
|
if (meta.titleArea) {
|
|
85
110
|
this.titleAreaSetContents(meta.titleArea.title, meta.titleArea.align);
|
|
86
|
-
if (meta.titleArea.show) {
|
|
111
|
+
if (meta.titleArea.show == true) {
|
|
87
112
|
this.titleAreaShow();
|
|
88
113
|
} else {
|
|
89
114
|
this.titleAreaHide();
|
|
@@ -91,6 +116,7 @@ var quikchat = /*#__PURE__*/function () {
|
|
|
91
116
|
}
|
|
92
117
|
this._attachEventListeners();
|
|
93
118
|
this.trackHistory = meta.trackHistory || true;
|
|
119
|
+
this._historyLimit = 10000000;
|
|
94
120
|
this._history = [];
|
|
95
121
|
}
|
|
96
122
|
return _createClass(quikchat, [{
|
|
@@ -106,9 +132,6 @@ var quikchat = /*#__PURE__*/function () {
|
|
|
106
132
|
this._sendButton = this._inputArea.querySelector('.quikchat-input-send-btn');
|
|
107
133
|
this.msgid = 0;
|
|
108
134
|
}
|
|
109
|
-
}, {
|
|
110
|
-
key: "$",
|
|
111
|
-
value: function $() {}
|
|
112
135
|
}, {
|
|
113
136
|
key: "_attachEventListeners",
|
|
114
137
|
value: function _attachEventListeners() {
|
|
@@ -131,6 +154,20 @@ var quikchat = /*#__PURE__*/function () {
|
|
|
131
154
|
}
|
|
132
155
|
});
|
|
133
156
|
}
|
|
157
|
+
// set the onSend function callback.
|
|
158
|
+
}, {
|
|
159
|
+
key: "setCallbackOnSend",
|
|
160
|
+
value: function setCallbackOnSend(callback) {
|
|
161
|
+
this._onSend = callback;
|
|
162
|
+
}
|
|
163
|
+
// set a callback for everytime a message is added (listener)
|
|
164
|
+
}, {
|
|
165
|
+
key: "setCallbackonMessageAdded",
|
|
166
|
+
value: function setCallbackonMessageAdded(callback) {
|
|
167
|
+
this._onMessageAdded = callback;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Public methods
|
|
134
171
|
}, {
|
|
135
172
|
key: "titleAreaToggle",
|
|
136
173
|
value: function titleAreaToggle() {
|
|
@@ -206,59 +243,67 @@ var quikchat = /*#__PURE__*/function () {
|
|
|
206
243
|
this._sendButton.style.minWidth = "".concat(minWidth, "px");
|
|
207
244
|
}
|
|
208
245
|
}, {
|
|
209
|
-
key: "
|
|
210
|
-
value: function
|
|
211
|
-
var
|
|
212
|
-
|
|
213
|
-
|
|
246
|
+
key: "messageAddFull",
|
|
247
|
+
value: function messageAddFull() {
|
|
248
|
+
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
249
|
+
content: "",
|
|
250
|
+
userString: "user",
|
|
251
|
+
align: "right",
|
|
252
|
+
role: "user",
|
|
253
|
+
userID: -1
|
|
254
|
+
};
|
|
214
255
|
var msgid = this.msgid;
|
|
256
|
+
var messageDiv = document.createElement('div');
|
|
215
257
|
var msgidClass = 'quikchat-msgid-' + String(msgid).padStart(10, '0');
|
|
258
|
+
'quikchat-userid-' + String(input.userString).padStart(10, '0'); // hash this..
|
|
216
259
|
messageDiv.classList.add('quikchat-message', msgidClass);
|
|
217
260
|
this.msgid++;
|
|
218
261
|
messageDiv.classList.add(this._messagesArea.children.length % 2 === 1 ? 'quikchat-message-1' : 'quikchat-message-2');
|
|
219
|
-
var user = {
|
|
220
|
-
name: "not-set",
|
|
221
|
-
role: "user"
|
|
222
|
-
};
|
|
223
|
-
if (_typeof(userObject) === 'object') {
|
|
224
|
-
for (var key in userObject) {
|
|
225
|
-
user[key] = userObject[key];
|
|
226
|
-
}
|
|
227
|
-
} else {
|
|
228
|
-
// if userObject is a string
|
|
229
|
-
user["name"] = userObject;
|
|
230
|
-
}
|
|
231
262
|
var userDiv = document.createElement('div');
|
|
232
|
-
userDiv.innerHTML =
|
|
233
|
-
userDiv.style = "width: 100%; text-align: ".concat(align, "; font-size: 1em; font-weight:700;
|
|
263
|
+
userDiv.innerHTML = input.userString;
|
|
264
|
+
userDiv.style = "width: 100%; text-align: ".concat(input.align, "; font-size: 1em; font-weight:700;");
|
|
234
265
|
var contentDiv = document.createElement('div');
|
|
235
|
-
contentDiv.style = "width: 100%; text-align: ".concat(align, ";");
|
|
236
|
-
contentDiv.innerHTML =
|
|
266
|
+
contentDiv.style = "width: 100%; text-align: ".concat(input.align, ";");
|
|
267
|
+
contentDiv.innerHTML = input.content;
|
|
237
268
|
messageDiv.appendChild(userDiv);
|
|
238
269
|
messageDiv.appendChild(contentDiv);
|
|
239
270
|
this._messagesArea.appendChild(messageDiv);
|
|
240
|
-
this._messagesArea.lastChild.scrollIntoView();
|
|
271
|
+
//this._messagesArea.lastChild.scrollIntoView();
|
|
272
|
+
this._messagesArea.lastElementChild.scrollIntoView();
|
|
241
273
|
this._textEntry.value = '';
|
|
242
274
|
this._adjustMessagesAreaHeight();
|
|
243
275
|
var timestamp = new Date().toISOString();
|
|
244
276
|
var updatedtime = timestamp;
|
|
245
277
|
if (this.trackHistory) {
|
|
246
|
-
this._history.push({
|
|
247
|
-
msgid: msgid
|
|
248
|
-
|
|
249
|
-
message: message,
|
|
250
|
-
align: align,
|
|
278
|
+
this._history.push(_objectSpread2(_objectSpread2({
|
|
279
|
+
msgid: msgid
|
|
280
|
+
}, input), {}, {
|
|
251
281
|
timestamp: timestamp,
|
|
252
282
|
updatedtime: updatedtime,
|
|
253
283
|
messageDiv: messageDiv
|
|
254
|
-
});
|
|
255
|
-
if (this._history.length >
|
|
284
|
+
}));
|
|
285
|
+
if (this._history.length > this._historyLimit) {
|
|
256
286
|
this._history.shift();
|
|
257
287
|
}
|
|
258
288
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
}
|
|
289
|
+
if (this._onMessageAdded) {
|
|
290
|
+
this._onMessageAdded(this, msgid);
|
|
291
|
+
}
|
|
292
|
+
return msgid;
|
|
293
|
+
}
|
|
294
|
+
}, {
|
|
295
|
+
key: "messageAddNew",
|
|
296
|
+
value: function messageAddNew() {
|
|
297
|
+
var content = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
|
|
298
|
+
var userString = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "user";
|
|
299
|
+
var align = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "right";
|
|
300
|
+
var role = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "user";
|
|
301
|
+
return this.messageAddFull({
|
|
302
|
+
content: content,
|
|
303
|
+
userString: userString,
|
|
304
|
+
align: align,
|
|
305
|
+
role: role
|
|
306
|
+
});
|
|
262
307
|
}
|
|
263
308
|
}, {
|
|
264
309
|
key: "messageRemove",
|
|
@@ -272,10 +317,13 @@ var quikchat = /*#__PURE__*/function () {
|
|
|
272
317
|
console.log("{String(n)} : Message ID not found");
|
|
273
318
|
}
|
|
274
319
|
if (sucess) {
|
|
275
|
-
// remove from history
|
|
276
|
-
this._history = this._history.filter(
|
|
277
|
-
|
|
278
|
-
|
|
320
|
+
// slow way to remove from history
|
|
321
|
+
//this._history = this._history.filter((item) => item.msgid !== n); // todo make this more efficient
|
|
322
|
+
|
|
323
|
+
// better way to delete this from history
|
|
324
|
+
this._history.splice(this._history.findIndex(function (item) {
|
|
325
|
+
return item.msgid === n;
|
|
326
|
+
}), 1);
|
|
279
327
|
}
|
|
280
328
|
return sucess;
|
|
281
329
|
}
|
|
@@ -301,7 +349,11 @@ var quikchat = /*#__PURE__*/function () {
|
|
|
301
349
|
var content = "";
|
|
302
350
|
// now use css selector to get the message
|
|
303
351
|
try {
|
|
304
|
-
|
|
352
|
+
// get from history..
|
|
353
|
+
content = this._history.filter(function (item) {
|
|
354
|
+
return item.msgid === n;
|
|
355
|
+
})[0].content;
|
|
356
|
+
//content = this._messagesArea.querySelector(`.quikchat-msgid-${String(n).padStart(10, '0')}`).lastChild.textContent;
|
|
305
357
|
} catch (error) {
|
|
306
358
|
console.log("{String(n)} : Message ID not found");
|
|
307
359
|
}
|
|
@@ -316,7 +368,15 @@ var quikchat = /*#__PURE__*/function () {
|
|
|
316
368
|
var sucess = false;
|
|
317
369
|
try {
|
|
318
370
|
this._messagesArea.querySelector(".quikchat-msgid-".concat(String(n).padStart(10, '0'))).lastChild.innerHTML += content;
|
|
371
|
+
// update history
|
|
372
|
+
var item = this._history.filter(function (item) {
|
|
373
|
+
return item.msgid === n;
|
|
374
|
+
})[0];
|
|
375
|
+
item.content += content;
|
|
376
|
+
item.updatedtime = new Date().toISOString();
|
|
319
377
|
sucess = true;
|
|
378
|
+
//this._messagesArea.lastChild.scrollIntoView();
|
|
379
|
+
this._messagesArea.lastElementChild.scrollIntoView();
|
|
320
380
|
} catch (error) {
|
|
321
381
|
console.log("{String(n)} : Message ID not found");
|
|
322
382
|
}
|
|
@@ -329,6 +389,10 @@ var quikchat = /*#__PURE__*/function () {
|
|
|
329
389
|
var sucess = false;
|
|
330
390
|
try {
|
|
331
391
|
this._messagesArea.querySelector(".quikchat-msgid-".concat(String(n).padStart(10, '0'))).lastChild.innerHTML = content;
|
|
392
|
+
// update history
|
|
393
|
+
this._history.filter(function (item) {
|
|
394
|
+
return item.msgid === n;
|
|
395
|
+
})[0].content = content;
|
|
332
396
|
sucess = true;
|
|
333
397
|
} catch (error) {
|
|
334
398
|
console.log("{String(n)} : Message ID not found");
|
|
@@ -352,6 +416,9 @@ var quikchat = /*#__PURE__*/function () {
|
|
|
352
416
|
if (m === undefined) {
|
|
353
417
|
m = n < 0 ? m : n + 1;
|
|
354
418
|
}
|
|
419
|
+
// remember that entries could be deleted. TODO: So we need to return the actual history entries
|
|
420
|
+
// so now we need to find the array index that correspondes to messageIds n (start) and m (end)
|
|
421
|
+
|
|
355
422
|
return this._history.slice(n, m);
|
|
356
423
|
}
|
|
357
424
|
}, {
|
|
@@ -391,10 +458,12 @@ var quikchat = /*#__PURE__*/function () {
|
|
|
391
458
|
return this._theme;
|
|
392
459
|
}
|
|
393
460
|
}], [{
|
|
394
|
-
key: "
|
|
395
|
-
value: function
|
|
461
|
+
key: "version",
|
|
462
|
+
value: function version() {
|
|
396
463
|
return {
|
|
397
|
-
"version": "1.0.
|
|
464
|
+
"version": "1.0.4",
|
|
465
|
+
"license": "BSD-2",
|
|
466
|
+
"url": "https://github/deftio/quikchat"
|
|
398
467
|
};
|
|
399
468
|
}
|
|
400
469
|
}]);
|