@descope/web-components-ui 1.0.305 → 1.0.306
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/index.cjs.js +31 -6
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/index.esm.js +31 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/umd/DescopeDev.js +1 -1
- package/dist/umd/descope-enriched-text-index-js.js +1 -1
- package/package.json +1 -1
- package/src/components/descope-enriched-text/EnrichedTextClass.js +31 -6
@@ -1 +1 @@
|
|
1
|
-
"use strict";(self.webpackChunk_descope_web_components_ui=self.webpackChunk_descope_web_components_ui||[]).push([[5158],{212:(e,t,n)=>{n.r(t),n.d(t,{EnrichedTextClass:()=>d});var
|
1
|
+
"use strict";(self.webpackChunk_descope_web_components_ui=self.webpackChunk_descope_web_components_ui||[]).push([[5158],{212:(e,t,n)=>{n.r(t),n.d(t,{EnrichedTextClass:()=>d});var r=n(4569),o=n(4978),s=n(2061),i=n(4567);const l={components:{core:{rules:["block","inline"]},block:{rules:["blockquote","code","heading","list","paragraph","list"]},inline:{rules:["backticks","strikethrough","link","emphasis","strikethrough","newline","text"]}}};var a=n(3346);const h=(0,i.iY)("enriched-text");class c extends((0,a.s)({componentName:h,baseSelector:":host > div"})){#e;constructor(){super(),this.attachShadow({mode:"open"}).innerHTML='\n <style>\n :host {\n display: inline-block;\n }\n :host > slot {\n width: 100%;\n display: inline-block;\n }\n *, *:last-child {\n margin: 0;\n }\n h1,\n h2,\n h3,\n h4,\n h5,\n h6,\n p {\n margin-bottom: 1em;\n }\n a {\n text-decoration: none;\n cursor: pointer;\n }\n a:hover {\n text-decoration: underline;\n }\n blockquote {\n padding: 0 2em;\n }\n </style>\n <slot part="text-wrapper" style="display:none"></slot>\n <div class="content"></div>\n ',this.textSlot=this.shadowRoot.querySelector("slot"),this.#t(),(0,i.P$)(this,this.#n.bind(this))}static get observedAttributes(){return["readonly","link-target-blank"]}attributeChangedCallback(e,t,n){super.attributeChangedCallback?.(e,t,n),n!==t&&("readonly"===e&&this.onReadOnlyChange("true"===n),"link-target-blank"===e&&this.#t())}#r(){this.linkTargetBlank?this.processor.renderer.rules.link_open=(e,t,n,r,o)=>(e[t].attrSet("target","_blank"),this.#e(e,t,n,r,o)):this.processor.renderer.rules.link_open=this.#e}#o(){if(!this.processor)return;const e=l;this.processor.configure(e||{})}#s(){this.#o()}#i(){this.#e=this.processor.renderer.rules.link_open||((e,t,n,r,o)=>o.renderToken(e,t,n))}#t(){this.processor=new r.Z,this.#i(),this.#s(),this.#r()}get linkTargetBlank(){return"true"===this.getAttribute("link-target-blank")}get contentNode(){return this.shadowRoot.querySelector(".content")}#n(){if(!this.processor)return;let e=this.textContent;try{const t=this.processor.parse(this.textContent,{references:void 0});e=this.processor.renderer.render(t,{breaks:!0})}catch(e){console.warn("Not parsing invalid markdown token")}this.contentNode.innerHTML=e}onReadOnlyChange(e){e?this.contentNode.setAttribute("inert",e):this.contentNode.removeAttribute("inert")}}const d=(0,s.qC)((0,o.yk)({mappings:{hostWidth:{selector:()=>":host",property:"width"},hostDirection:{selector:()=>":host",property:"direction"},fontSize:{},fontFamily:{},fontWeight:{},textColor:{property:"color"},textLineHeight:{property:"line-height"},textAlign:{},linkColor:{selector:"a",property:"color"}}}),(0,o.yk)({componentNameOverride:(0,i.iY)("link")}),o.e4,o.Ae)(c);customElements.define(h,d)}}]);
|
package/package.json
CHANGED
@@ -8,7 +8,7 @@ import { createBaseClass } from '../../baseClasses/createBaseClass';
|
|
8
8
|
export const componentName = getComponentName('enriched-text');
|
9
9
|
|
10
10
|
class EnrichedText extends createBaseClass({ componentName, baseSelector: ':host > div' }) {
|
11
|
-
#
|
11
|
+
#origLinkRenderer;
|
12
12
|
|
13
13
|
constructor() {
|
14
14
|
super();
|
@@ -57,7 +57,7 @@ class EnrichedText extends createBaseClass({ componentName, baseSelector: ':host
|
|
57
57
|
}
|
58
58
|
|
59
59
|
static get observedAttributes() {
|
60
|
-
return ['readonly'];
|
60
|
+
return ['readonly', 'link-target-blank'];
|
61
61
|
}
|
62
62
|
|
63
63
|
attributeChangedCallback(attrName, oldValue, newValue) {
|
@@ -67,6 +67,23 @@ class EnrichedText extends createBaseClass({ componentName, baseSelector: ':host
|
|
67
67
|
if (attrName === 'readonly') {
|
68
68
|
this.onReadOnlyChange(newValue === 'true');
|
69
69
|
}
|
70
|
+
|
71
|
+
if (attrName === 'link-target-blank') {
|
72
|
+
this.#initProcessor();
|
73
|
+
}
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
#customizeLinkRenderer() {
|
78
|
+
if (this.linkTargetBlank) {
|
79
|
+
this.processor.renderer.rules.link_open = (tokens, idx, options, env, self) => {
|
80
|
+
// Add a new `target` attribute, or replace the value of the existing one.
|
81
|
+
tokens[idx].attrSet('target', '_blank');
|
82
|
+
// Pass the token to the default renderer.
|
83
|
+
return this.#origLinkRenderer(tokens, idx, options, env, self);
|
84
|
+
};
|
85
|
+
} else {
|
86
|
+
this.processor.renderer.rules.link_open = this.#origLinkRenderer;
|
70
87
|
}
|
71
88
|
}
|
72
89
|
|
@@ -77,19 +94,27 @@ class EnrichedText extends createBaseClass({ componentName, baseSelector: ':host
|
|
77
94
|
|
78
95
|
const customRuleSet = textRuleSet;
|
79
96
|
this.processor.configure(customRuleSet || {});
|
80
|
-
|
81
|
-
if (customRuleSet?.custom?.includes('image')) {
|
82
|
-
this.processor.renderer.rules.image = this.#origImageRenderer;
|
83
|
-
}
|
84
97
|
}
|
85
98
|
|
86
99
|
#updateProcessorRules() {
|
87
100
|
this.#enableCustomRules();
|
88
101
|
}
|
89
102
|
|
103
|
+
#storeOrigRenderers() {
|
104
|
+
const defaultLinkRenderer = (tokens, idx, options, _, self) =>
|
105
|
+
self.renderToken(tokens, idx, options);
|
106
|
+
this.#origLinkRenderer = this.processor.renderer.rules.link_open || defaultLinkRenderer;
|
107
|
+
}
|
108
|
+
|
90
109
|
#initProcessor() {
|
91
110
|
this.processor = new MarkdownIt();
|
111
|
+
this.#storeOrigRenderers();
|
92
112
|
this.#updateProcessorRules();
|
113
|
+
this.#customizeLinkRenderer();
|
114
|
+
}
|
115
|
+
|
116
|
+
get linkTargetBlank() {
|
117
|
+
return this.getAttribute('link-target-blank') === 'true';
|
93
118
|
}
|
94
119
|
|
95
120
|
get contentNode() {
|