@telia-ace/widget-conversation-flamingo 1.1.72-rc.13 → 1.1.72-rc.15

Sign up to get free protection for your applications and to get access to all the features.
package/index.js CHANGED
@@ -727,7 +727,7 @@ ${e}</tr>
727
727
  `}tablecell(e,t){const n=t.header?"th":"td";return(t.align?`<${n} align="${t.align}">`:`<${n}>`)+e+`</${n}>
728
728
  `}strong(e){return`<strong>${e}</strong>`}em(e){return`<em>${e}</em>`}codespan(e){return`<code>${e}</code>`}br(){return"<br>"}del(e){return`<del>${e}</del>`}link(e,t,n){const i=hs(e);if(i===null)return n;e=i;let r='<a href="'+e+'"';return t&&(r+=' title="'+t+'"'),r+=">"+n+"</a>",r}image(e,t,n){const i=hs(e);if(i===null)return n;e=i;let r=`<img src="${e}" alt="${n}"`;return t&&(r+=` title="${t}"`),r+=">",r}text(e){return e}}class xn{strong(e){return e}em(e){return e}codespan(e){return e}del(e){return e}html(e){return e}text(e){return e}link(e,t,n){return""+n}image(e,t,n){return""+n}br(){return""}}class D{constructor(e){x(this,"options");x(this,"renderer");x(this,"textRenderer");this.options=e||ae,this.options.renderer=this.options.renderer||new ot,this.renderer=this.options.renderer,this.renderer.options=this.options,this.textRenderer=new xn}static parse(e,t){return new D(t).parse(e)}static parseInline(e,t){return new D(t).parseInline(e)}parse(e,t=!0){let n="";for(let i=0;i<e.length;i++){const r=e[i];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){const o=r,a=this.options.extensions.renderers[o.type].call({parser:this},o);if(a!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(o.type)){n+=a||"";continue}}switch(r.type){case"space":continue;case"hr":{n+=this.renderer.hr();continue}case"heading":{const o=r;n+=this.renderer.heading(this.parseInline(o.tokens),o.depth,el(this.parseInline(o.tokens,this.textRenderer)));continue}case"code":{const o=r;n+=this.renderer.code(o.text,o.lang,!!o.escaped);continue}case"table":{const o=r;let a="",l="";for(let h=0;h<o.header.length;h++)l+=this.renderer.tablecell(this.parseInline(o.header[h].tokens),{header:!0,align:o.align[h]});a+=this.renderer.tablerow(l);let c="";for(let h=0;h<o.rows.length;h++){const u=o.rows[h];l="";for(let p=0;p<u.length;p++)l+=this.renderer.tablecell(this.parseInline(u[p].tokens),{header:!1,align:o.align[p]});c+=this.renderer.tablerow(l)}n+=this.renderer.table(a,c);continue}case"blockquote":{const o=r,a=this.parse(o.tokens);n+=this.renderer.blockquote(a);continue}case"list":{const o=r,a=o.ordered,l=o.start,c=o.loose;let h="";for(let u=0;u<o.items.length;u++){const p=o.items[u],d=p.checked,b=p.task;let f="";if(p.task){const I=this.renderer.checkbox(!!d);c?p.tokens.length>0&&p.tokens[0].type==="paragraph"?(p.tokens[0].text=I+" "+p.tokens[0].text,p.tokens[0].tokens&&p.tokens[0].tokens.length>0&&p.tokens[0].tokens[0].type==="text"&&(p.tokens[0].tokens[0].text=I+" "+p.tokens[0].tokens[0].text)):p.tokens.unshift({type:"text",text:I+" "}):f+=I+" "}f+=this.parse(p.tokens,c),h+=this.renderer.listitem(f,b,!!d)}n+=this.renderer.list(h,a,l);continue}case"html":{const o=r;n+=this.renderer.html(o.text,o.block);continue}case"paragraph":{const o=r;n+=this.renderer.paragraph(this.parseInline(o.tokens));continue}case"text":{let o=r,a=o.tokens?this.parseInline(o.tokens):o.text;for(;i+1<e.length&&e[i+1].type==="text";)o=e[++i],a+=`
729
729
  `+(o.tokens?this.parseInline(o.tokens):o.text);n+=t?this.renderer.paragraph(a):a;continue}default:{const o='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return n}parseInline(e,t){t=t||this.renderer;let n="";for(let i=0;i<e.length;i++){const r=e[i];if(this.options.extensions&&this.options.extensions.renderers&&this.options.extensions.renderers[r.type]){const o=this.options.extensions.renderers[r.type].call({parser:this},r);if(o!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(r.type)){n+=o||"";continue}}switch(r.type){case"escape":{const o=r;n+=t.text(o.text);break}case"html":{const o=r;n+=t.html(o.text);break}case"link":{const o=r;n+=t.link(o.href,o.title,this.parseInline(o.tokens,t));break}case"image":{const o=r;n+=t.image(o.href,o.title,o.text);break}case"strong":{const o=r;n+=t.strong(this.parseInline(o.tokens,t));break}case"em":{const o=r;n+=t.em(this.parseInline(o.tokens,t));break}case"codespan":{const o=r;n+=t.codespan(o.text);break}case"br":{n+=t.br();break}case"del":{const o=r;n+=t.del(this.parseInline(o.tokens,t));break}case"text":{const o=r;n+=t.text(o.text);break}default:{const o='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return n}}class Ce{constructor(e){x(this,"options");this.options=e||ae}preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}}x(Ce,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens"]));var Oe,Zt,at,Ai;class Ll{constructor(...e){$t(this,Oe);$t(this,at);x(this,"defaults",gn());x(this,"options",this.setOptions);x(this,"parse",Be(this,Oe,Zt).call(this,j.lex,D.parse));x(this,"parseInline",Be(this,Oe,Zt).call(this,j.lexInline,D.parseInline));x(this,"Parser",D);x(this,"Renderer",ot);x(this,"TextRenderer",xn);x(this,"Lexer",j);x(this,"Tokenizer",it);x(this,"Hooks",Ce);this.use(...e)}walkTokens(e,t){var i,r;let n=[];for(const o of e)switch(n=n.concat(t.call(this,o)),o.type){case"table":{const a=o;for(const l of a.header)n=n.concat(this.walkTokens(l.tokens,t));for(const l of a.rows)for(const c of l)n=n.concat(this.walkTokens(c.tokens,t));break}case"list":{const a=o;n=n.concat(this.walkTokens(a.items,t));break}default:{const a=o;(r=(i=this.defaults.extensions)==null?void 0:i.childTokens)!=null&&r[a.type]?this.defaults.extensions.childTokens[a.type].forEach(l=>{const c=a[l].flat(1/0);n=n.concat(this.walkTokens(c,t))}):a.tokens&&(n=n.concat(this.walkTokens(a.tokens,t)))}}return n}use(...e){const t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(n=>{const i={...n};if(i.async=this.defaults.async||i.async||!1,n.extensions&&(n.extensions.forEach(r=>{if(!r.name)throw new Error("extension name required");if("renderer"in r){const o=t.renderers[r.name];o?t.renderers[r.name]=function(...a){let l=r.renderer.apply(this,a);return l===!1&&(l=o.apply(this,a)),l}:t.renderers[r.name]=r.renderer}if("tokenizer"in r){if(!r.level||r.level!=="block"&&r.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");const o=t[r.level];o?o.unshift(r.tokenizer):t[r.level]=[r.tokenizer],r.start&&(r.level==="block"?t.startBlock?t.startBlock.push(r.start):t.startBlock=[r.start]:r.level==="inline"&&(t.startInline?t.startInline.push(r.start):t.startInline=[r.start]))}"childTokens"in r&&r.childTokens&&(t.childTokens[r.name]=r.childTokens)}),i.extensions=t),n.renderer){const r=this.defaults.renderer||new ot(this.defaults);for(const o in n.renderer){if(!(o in r))throw new Error(`renderer '${o}' does not exist`);if(o==="options")continue;const a=o,l=n.renderer[a],c=r[a];r[a]=(...h)=>{let u=l.apply(r,h);return u===!1&&(u=c.apply(r,h)),u||""}}i.renderer=r}if(n.tokenizer){const r=this.defaults.tokenizer||new it(this.defaults);for(const o in n.tokenizer){if(!(o in r))throw new Error(`tokenizer '${o}' does not exist`);if(["options","rules","lexer"].includes(o))continue;const a=o,l=n.tokenizer[a],c=r[a];r[a]=(...h)=>{let u=l.apply(r,h);return u===!1&&(u=c.apply(r,h)),u}}i.tokenizer=r}if(n.hooks){const r=this.defaults.hooks||new Ce;for(const o in n.hooks){if(!(o in r))throw new Error(`hook '${o}' does not exist`);if(o==="options")continue;const a=o,l=n.hooks[a],c=r[a];Ce.passThroughHooks.has(o)?r[a]=h=>{if(this.defaults.async)return Promise.resolve(l.call(r,h)).then(p=>c.call(r,p));const u=l.call(r,h);return c.call(r,u)}:r[a]=(...h)=>{let u=l.apply(r,h);return u===!1&&(u=c.apply(r,h)),u}}i.hooks=r}if(n.walkTokens){const r=this.defaults.walkTokens,o=n.walkTokens;i.walkTokens=function(a){let l=[];return l.push(o.call(this,a)),r&&(l=l.concat(r.call(this,a))),l}}this.defaults={...this.defaults,...i}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return j.lex(e,t??this.defaults)}parser(e,t){return D.parse(e,t??this.defaults)}}Oe=new WeakSet,Zt=function(e,t){return(n,i)=>{const r={...i},o={...this.defaults,...r};this.defaults.async===!0&&r.async===!1&&(o.silent||console.warn("marked(): The async option was set to true by an extension. The async: false option sent to parse will be ignored."),o.async=!0);const a=Be(this,at,Ai).call(this,!!o.silent,!!o.async);if(typeof n>"u"||n===null)return a(new Error("marked(): input parameter is undefined or null"));if(typeof n!="string")return a(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(n)+", string expected"));if(o.hooks&&(o.hooks.options=o),o.async)return Promise.resolve(o.hooks?o.hooks.preprocess(n):n).then(l=>e(l,o)).then(l=>o.hooks?o.hooks.processAllTokens(l):l).then(l=>o.walkTokens?Promise.all(this.walkTokens(l,o.walkTokens)).then(()=>l):l).then(l=>t(l,o)).then(l=>o.hooks?o.hooks.postprocess(l):l).catch(a);try{o.hooks&&(n=o.hooks.preprocess(n));let l=e(n,o);o.hooks&&(l=o.hooks.processAllTokens(l)),o.walkTokens&&this.walkTokens(l,o.walkTokens);let c=t(l,o);return o.hooks&&(c=o.hooks.postprocess(c)),c}catch(l){return a(l)}}},at=new WeakSet,Ai=function(e,t){return n=>{if(n.message+=`
730
- Please report this to https://github.com/markedjs/marked.`,e){const i="<p>An error occurred:</p><pre>"+L(n.message+"",!0)+"</pre>";return t?Promise.resolve(i):i}if(t)return Promise.reject(n);throw n}};const oe=new Ll;function v(s,e){return oe.parse(s,e)}v.options=v.setOptions=function(s){return oe.setOptions(s),v.defaults=oe.defaults,vi(v.defaults),v};v.getDefaults=gn;v.defaults=ae;v.use=function(...s){return oe.use(...s),v.defaults=oe.defaults,vi(v.defaults),v};v.walkTokens=function(s,e){return oe.walkTokens(s,e)};v.parseInline=oe.parseInline;v.Parser=D;v.parser=D.parse;v.Renderer=ot;v.TextRenderer=xn;v.Lexer=j;v.lexer=j.lex;v.Tokenizer=it;v.Hooks=Ce;v.parse=v;v.options;v.setOptions;v.use;v.walkTokens;v.parseInline;D.parse;j.lex;var Ol=Object.defineProperty,Pl=Object.getOwnPropertyDescriptor,Ei=(s,e,t,n)=>{for(var i=n>1?void 0:n?Pl(e,t):e,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Ol(e,t,i),i};v.use({renderer:{link(s,e,t){return e||(e=t),`<a target="_blank" href="${s}" title="${e}">${t}</a>`}}});class bt extends k{constructor(){super(...arguments),this.showLightbox=!1,this.imageUrl="",this.altText="",this.scrollRef=M(),this.contentRef=M(),this.autoScroll=!0,this.buffer="",this.pointer=0,this.imageRegexp=new RegExp(/!\[[^[]*\([^)]*\)/gm),this.includesImage=e=>this.imageRegexp.test(e)}handleAutoscroll(){this.addEventListener("wheel",()=>{this.autoScroll=!1},{passive:!0}),this.addEventListener("click",()=>{this.autoScroll=!1})}handleLightboxClose(){this.addEventListener("action",e=>{e.detail.key==="close-lightbox"&&(this.showLightbox=!1)})}handleLightboxOpen(){this.contentRef.value.addEventListener("click",e=>{e.target.tagName==="IMG"&&(this.showLightbox=!0,this.imageUrl=e.target.src,this.altText=e.target.alt)})}getLastChunk(){const e=this.message.content.length-this.pointer;return e===0?"":(this.pointer=this.message.content.length,this.message.content.slice(-e))}async firstUpdated(){this.handleAutoscroll(),this.handleLightboxOpen(),this.handleLightboxClose()}updated(){var i,r;const e=this.getLastChunk();if(!e)return;this.buffer+=e;const t=v.parse(this.buffer),n=(i=this.contentRef.value)==null?void 0:i.querySelector("div:last-of-type");if(this.includesImage(this.buffer))(r=this.contentRef.value)==null||r.appendChild(document.createElement("div")),this.buffer="";else if(this.buffer.includes("!["))return;n.innerHTML=zs(t),this.autoScroll&&this.scrollRef.value.scrollIntoView()}render(){return m`
730
+ Please report this to https://github.com/markedjs/marked.`,e){const i="<p>An error occurred:</p><pre>"+L(n.message+"",!0)+"</pre>";return t?Promise.resolve(i):i}if(t)return Promise.reject(n);throw n}};const oe=new Ll;function v(s,e){return oe.parse(s,e)}v.options=v.setOptions=function(s){return oe.setOptions(s),v.defaults=oe.defaults,vi(v.defaults),v};v.getDefaults=gn;v.defaults=ae;v.use=function(...s){return oe.use(...s),v.defaults=oe.defaults,vi(v.defaults),v};v.walkTokens=function(s,e){return oe.walkTokens(s,e)};v.parseInline=oe.parseInline;v.Parser=D;v.parser=D.parse;v.Renderer=ot;v.TextRenderer=xn;v.Lexer=j;v.lexer=j.lex;v.Tokenizer=it;v.Hooks=Ce;v.parse=v;v.options;v.setOptions;v.use;v.walkTokens;v.parseInline;D.parse;j.lex;var Ol=Object.defineProperty,Pl=Object.getOwnPropertyDescriptor,Ei=(s,e,t,n)=>{for(var i=n>1?void 0:n?Pl(e,t):e,r=s.length-1,o;r>=0;r--)(o=s[r])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Ol(e,t,i),i};v.use({renderer:{link(s,e,t){return e||(e=t),`<a target="_blank" href="${s}" title="${e}">${t}</a>`}}});class bt extends k{constructor(){super(...arguments),this.showLightbox=!1,this.imageUrl="",this.altText="",this.scrollRef=M(),this.contentRef=M(),this.autoScroll=!0,this.buffer="",this.pointer=0,this.imageRegexp=new RegExp(/!\[[^[]*\([^)]*\)/gm),this.includesImage=e=>this.imageRegexp.test(e)}handleAutoscroll(){this.addEventListener("wheel",()=>{this.autoScroll=!1},{passive:!0}),this.addEventListener("click",()=>{this.autoScroll=!1})}handleLightboxClose(){this.addEventListener("action",e=>{e.detail.key==="close-lightbox"&&(this.showLightbox=!1)})}handleLightboxOpen(){this.contentRef.value.addEventListener("click",e=>{e.target.tagName==="IMG"&&(this.showLightbox=!0,this.imageUrl=e.target.src,this.altText=e.target.alt)})}getLastChunk(){const e=this.message.content.length-this.pointer;return e===0?"":(this.pointer=this.message.content.length,this.message.content.slice(-e))}async firstUpdated(){this.handleAutoscroll(),this.handleLightboxOpen(),this.handleLightboxClose()}updated(){var i,r;const e=this.getLastChunk();if(!e)return;this.buffer+=e;const t=v.parse(this.buffer),n=(i=this.contentRef.value)==null?void 0:i.querySelector("div:last-of-type");if(this.includesImage(this.buffer))(r=this.contentRef.value)==null||r.appendChild(document.createElement("div")),this.buffer="";else if(this.buffer.includes("!["))return;n.innerHTML=zs(t),this.applyCodeStyles(n),this.autoScroll&&this.scrollRef.value.scrollIntoView()}applyCodeStyles(e){if(!e)return;e.querySelectorAll("code").forEach(n=>{n.style.whiteSpace="pre-wrap"})}render(){return m`
731
731
  <div class="message-type-markdown" ${z(this.contentRef)}>
732
732
  <div></div>
733
733
  </div>
package/index.mjs CHANGED
@@ -6088,7 +6088,15 @@ class bt extends k {
6088
6088
  (r = this.contentRef.value) == null || r.appendChild(document.createElement("div")), this.buffer = "";
6089
6089
  else if (this.buffer.includes("!["))
6090
6090
  return;
6091
- n.innerHTML = _r(t), this.autoScroll && this.scrollRef.value.scrollIntoView();
6091
+ n.innerHTML = _r(t), this.applyCodeStyles(n), this.autoScroll && this.scrollRef.value.scrollIntoView();
6092
+ }
6093
+ // Apply white-space: pre-wrap to <code> elements
6094
+ applyCodeStyles(e) {
6095
+ if (!e)
6096
+ return;
6097
+ e.querySelectorAll("code").forEach((n) => {
6098
+ n.style.whiteSpace = "pre-wrap";
6099
+ });
6092
6100
  }
6093
6101
  render() {
6094
6102
  return m`
@@ -20,5 +20,6 @@ export declare class MessageTypeMarkdown extends LitElement {
20
20
  private getLastChunk;
21
21
  firstUpdated(): Promise<void>;
22
22
  updated(): void;
23
+ private applyCodeStyles;
23
24
  render(): import("lit-html").TemplateResult<1>;
24
25
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@telia-ace/widget-conversation-flamingo",
3
- "version": "1.1.72-rc.13",
3
+ "version": "1.1.72-rc.15",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org"
6
6
  },
@@ -9,7 +9,7 @@
9
9
  "@lit-labs/motion": "^1.0.4",
10
10
  "@teliads/icons": "^8.4.0",
11
11
  "@teliads/components": "^22.1.1",
12
- "@telia-ace/widget-core-flamingo": "1.1.72-rc.13",
12
+ "@telia-ace/widget-core-flamingo": "1.1.72-rc.15",
13
13
  "lit-html": "^3.0.2",
14
14
  "rxjs": "^7.8.1",
15
15
  "marked": "^12.0.2"