@descope/web-components-ui 2.1.18 → 2.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 (53) hide show
  1. package/dist/cjs/index.cjs.js +273 -249
  2. package/dist/cjs/index.cjs.js.map +1 -1
  3. package/dist/index.esm.js +8072 -8025
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/umd/1899.js +1 -1
  6. package/dist/umd/1899.js.map +1 -1
  7. package/dist/umd/4623.js +1 -1
  8. package/dist/umd/4623.js.map +1 -1
  9. package/dist/umd/4914.js +1 -1
  10. package/dist/umd/4914.js.map +1 -1
  11. package/dist/umd/5648.js +1 -1
  12. package/dist/umd/5648.js.map +1 -1
  13. package/dist/umd/9582.js +2 -0
  14. package/dist/umd/9582.js.map +1 -0
  15. package/dist/umd/DescopeDev.js +1 -1
  16. package/dist/umd/DescopeDev.js.map +1 -1
  17. package/dist/umd/boolean-fields-descope-boolean-field-internal-index-js.js +1 -1
  18. package/dist/umd/boolean-fields-descope-boolean-field-internal-index-js.js.map +1 -1
  19. package/dist/umd/boolean-fields-descope-checkbox-index-js.js +1 -1
  20. package/dist/umd/boolean-fields-descope-checkbox-index-js.js.map +1 -1
  21. package/dist/umd/boolean-fields-descope-switch-toggle-index-js.js +1 -1
  22. package/dist/umd/boolean-fields-descope-switch-toggle-index-js.js.map +1 -1
  23. package/dist/umd/descope-alert-index-js.js +1 -1
  24. package/dist/umd/descope-alert-index-js.js.map +1 -1
  25. package/dist/umd/descope-email-field-index-js.js +1 -1
  26. package/dist/umd/descope-email-field-index-js.js.map +1 -1
  27. package/dist/umd/descope-enriched-text.js +1 -1
  28. package/dist/umd/descope-enriched-text.js.map +1 -1
  29. package/dist/umd/descope-grid-descope-grid-selection-column-index-js.js +1 -1
  30. package/dist/umd/descope-grid-descope-grid-selection-column-index-js.js.map +1 -1
  31. package/dist/umd/descope-grid-index-js.js +1 -1
  32. package/dist/umd/descope-grid-index-js.js.map +1 -1
  33. package/dist/umd/descope-passcode-index-js.js +1 -1
  34. package/dist/umd/descope-passcode-index-js.js.map +1 -1
  35. package/dist/umd/descope-scopes-list-index-js.js +1 -1
  36. package/dist/umd/descope-scopes-list-index-js.js.map +1 -1
  37. package/dist/umd/descope-security-questions-verify-index-js.js +1 -1
  38. package/dist/umd/descope-security-questions-verify-index-js.js.map +1 -1
  39. package/dist/umd/descope-text-field-index-js.js +1 -1
  40. package/dist/umd/descope-text-field-index-js.js.map +1 -1
  41. package/dist/umd/index.js +1 -1
  42. package/dist/umd/index.js.map +1 -1
  43. package/dist/umd/phone-fields-descope-phone-input-box-field-descope-phone-input-box-internal-index-js.js +1 -1
  44. package/dist/umd/phone-fields-descope-phone-input-box-field-descope-phone-input-box-internal-index-js.js.map +1 -1
  45. package/dist/umd/phone-fields-descope-phone-input-box-field-index-js.js +1 -1
  46. package/dist/umd/phone-fields-descope-phone-input-box-field-index-js.js.map +1 -1
  47. package/package.json +28 -28
  48. package/src/components/boolean-fields/commonStyles.js +11 -1
  49. package/src/components/boolean-fields/descope-boolean-field-internal/BooleanFieldInternal.js +32 -4
  50. package/src/components/boolean-fields/descope-checkbox/CheckboxClass.js +15 -2
  51. package/src/components/boolean-fields/descope-checkbox/index.js +1 -0
  52. package/src/components/boolean-fields/descope-switch-toggle/SwitchToggleClass.js +5 -2
  53. package/src/components/boolean-fields/descope-switch-toggle/index.js +1 -0
@@ -6142,6 +6142,230 @@ var textArea$1 = /*#__PURE__*/Object.freeze({
6142
6142
  vars: vars$Y
6143
6143
  });
6144
6144
 
6145
+ const disableRules = [
6146
+ 'blockquote',
6147
+ 'list',
6148
+ 'image',
6149
+ 'table',
6150
+ 'code',
6151
+ 'hr',
6152
+ 'backticks',
6153
+ 'fence',
6154
+ 'reference',
6155
+ 'heading',
6156
+ 'lheading',
6157
+ 'html_block',
6158
+ ];
6159
+
6160
+ const decodeHTML = (html) => {
6161
+ const textArea = document.createElement('textarea');
6162
+ textArea.innerHTML = html;
6163
+ return textArea.value;
6164
+ };
6165
+
6166
+ /* eslint-disable no-param-reassign */
6167
+
6168
+
6169
+ const componentName$16 = getComponentName('enriched-text');
6170
+
6171
+ class EnrichedText extends createBaseClass$1({ componentName: componentName$16, baseSelector: ':host > div' }) {
6172
+ #origLinkRenderer;
6173
+
6174
+ #origEmRenderer;
6175
+
6176
+ constructor() {
6177
+ super();
6178
+
6179
+ this.attachShadow({ mode: 'open' }).innerHTML = `
6180
+ <div class="content"></div>
6181
+ `;
6182
+
6183
+ injectStyle(
6184
+ `
6185
+ :host {
6186
+ line-height: 1em;
6187
+ word-break: break-word;
6188
+ }
6189
+ :host > slot {
6190
+ width: 100%;
6191
+ display: inline-block;
6192
+ }
6193
+ *, *:last-child {
6194
+ margin: 0;
6195
+ }
6196
+ h1,
6197
+ h2,
6198
+ h3,
6199
+ h4,
6200
+ h5,
6201
+ h6,
6202
+ p {
6203
+ margin-bottom: 1em;
6204
+ }
6205
+ a {
6206
+ cursor: pointer;
6207
+ }
6208
+ blockquote {
6209
+ padding: 0 2em;
6210
+ }
6211
+ u {
6212
+ text-decoration: underline
6213
+ }
6214
+ s {
6215
+ color: currentColor;
6216
+ }
6217
+ `,
6218
+ this
6219
+ );
6220
+
6221
+ this.#initProcessor();
6222
+
6223
+ observeChildren(this, this.#parseChildren.bind(this));
6224
+ }
6225
+
6226
+ static get observedAttributes() {
6227
+ return ['readonly', 'link-target-blank'];
6228
+ }
6229
+
6230
+ attributeChangedCallback(attrName, oldValue, newValue) {
6231
+ super.attributeChangedCallback?.(attrName, oldValue, newValue);
6232
+
6233
+ if (newValue !== oldValue) {
6234
+ if (attrName === 'readonly') {
6235
+ this.onReadOnlyChange(newValue === 'true');
6236
+ }
6237
+
6238
+ if (attrName === 'link-target-blank') {
6239
+ this.#initProcessor();
6240
+ }
6241
+ }
6242
+ }
6243
+
6244
+ // We're overriding the rule for em with single underscore to perform as underline. (_underline_)
6245
+ customUnderlineRenderer() {
6246
+ this.processor.renderer.rules.em_open = (tokens, idx, options, env, self) => {
6247
+ if (tokens[idx].markup === '_') tokens[idx].tag = 'u';
6248
+ return this.#origEmRenderer(tokens, idx, options, env, self);
6249
+ };
6250
+ this.processor.renderer.rules.em_close = (tokens, idx, options, env, self) => {
6251
+ if (tokens[idx].markup === '_') tokens[idx].tag = 'u';
6252
+ return this.#origEmRenderer(tokens, idx, options, env, self);
6253
+ };
6254
+ }
6255
+
6256
+ #customizeLinkRenderer() {
6257
+ if (this.linkTargetBlank) {
6258
+ this.processor.renderer.rules.link_open = (tokens, idx, options, env, self) => {
6259
+ // Add a new `target` attribute, or replace the value of the existing one.
6260
+ tokens[idx].attrSet('target', '_blank');
6261
+ // Pass the token to the default renderer.
6262
+ return this.#origLinkRenderer(tokens, idx, options, env, self);
6263
+ };
6264
+ } else {
6265
+ this.processor.renderer.rules.link_open = this.#origLinkRenderer;
6266
+ }
6267
+ }
6268
+
6269
+ #disableCustomRules() {
6270
+ if (!this.processor) {
6271
+ return;
6272
+ }
6273
+ this.processor.disable(disableRules);
6274
+ }
6275
+
6276
+ #updateProcessorRules() {
6277
+ this.#disableCustomRules();
6278
+ }
6279
+
6280
+ #storeOrigRenderers() {
6281
+ const defaultLinkRenderer = (tokens, idx, options, _, self) =>
6282
+ self.renderToken(tokens, idx, options);
6283
+ this.#origLinkRenderer = this.processor.renderer.rules.link_open || defaultLinkRenderer;
6284
+
6285
+ const defaultStrongRenderer = (tokens, idx, options, _, self) =>
6286
+ self.renderToken(tokens, idx, options);
6287
+ this.#origEmRenderer = this.processor.renderer.rules.em_open || defaultStrongRenderer;
6288
+ }
6289
+
6290
+ #initProcessor() {
6291
+ this.processor = new MarkdownIt('commonmark', { html: true });
6292
+ this.#storeOrigRenderers();
6293
+ this.#updateProcessorRules();
6294
+ this.#customizeLinkRenderer();
6295
+ this.customUnderlineRenderer();
6296
+ }
6297
+
6298
+ get linkTargetBlank() {
6299
+ return this.getAttribute('link-target-blank') === 'true';
6300
+ }
6301
+
6302
+ get contentNode() {
6303
+ return this.shadowRoot.querySelector('.content');
6304
+ }
6305
+
6306
+ #parseChildren() {
6307
+ if (!this.processor) {
6308
+ return;
6309
+ }
6310
+
6311
+ let html = decodeHTML(this.innerHTML);
6312
+
6313
+ if (!html?.trim() && this.isConnected) {
6314
+ this.setAttribute('empty', 'true');
6315
+ } else {
6316
+ this.removeAttribute('empty');
6317
+ }
6318
+
6319
+ try {
6320
+ const tokens = this.processor.parse(html, { references: undefined });
6321
+ html = this.processor.renderer.render(tokens, { html: true, breaks: true });
6322
+ } catch (e) {
6323
+ // eslint-disable-next-line no-console
6324
+ console.warn('Not parsing invalid markdown token');
6325
+ }
6326
+
6327
+ this.contentNode.innerHTML = html;
6328
+ this.contentNode.firstChild?.setAttribute('part', 'content');
6329
+ }
6330
+
6331
+ onReadOnlyChange(isReadOnly) {
6332
+ if (isReadOnly) {
6333
+ this.contentNode.setAttribute('inert', isReadOnly);
6334
+ } else {
6335
+ this.contentNode.removeAttribute('inert');
6336
+ }
6337
+ }
6338
+ }
6339
+
6340
+ const EnrichedTextClass = compose(
6341
+ createStyleMixin$1({
6342
+ mappings: {
6343
+ hostWidth: { selector: () => ':host', property: 'width' },
6344
+ hostDisplay: { selector: () => ':host', property: 'display', fallback: 'inline-block' },
6345
+ hostDirection: { selector: () => ':host', property: 'direction' },
6346
+ fontSize: {},
6347
+ fontFamily: {},
6348
+ fontWeight: {},
6349
+ fontWeightBold: [
6350
+ { selector: () => ':host strong', property: 'font-weight' },
6351
+ { selector: () => ':host b', property: 'font-weight' },
6352
+ ],
6353
+ textColor: { property: 'color' },
6354
+ textLineHeight: { property: 'line-height' },
6355
+ textAlign: {},
6356
+ linkColor: { selector: 'a', property: 'color' },
6357
+ linkTextDecoration: { selector: 'a', property: 'text-decoration' },
6358
+ linkHoverTextDecoration: { selector: 'a:hover', property: 'text-decoration' },
6359
+ minHeight: {},
6360
+ minWidth: {},
6361
+ },
6362
+ }),
6363
+ createStyleMixin$1({ componentNameOverride: getComponentName('link') }),
6364
+ createStyleMixin$1({ componentNameOverride: getComponentName('text') }),
6365
+ draggableMixin$1,
6366
+ componentNameValidationMixin$1
6367
+ )(EnrichedText);
6368
+
6145
6369
  const createBaseInputClass = (...args) =>
6146
6370
  compose$1(
6147
6371
  inputValidationMixin,
@@ -6150,9 +6374,9 @@ const createBaseInputClass = (...args) =>
6150
6374
  inputEventsDispatchingMixin
6151
6375
  )(createBaseClass(...args));
6152
6376
 
6153
- const componentName$16 = getComponentName$1('boolean-field-internal');
6377
+ const componentName$15 = getComponentName$1('boolean-field-internal');
6154
6378
 
6155
- createBaseInputClass({ componentName: componentName$16, baseSelector: 'div' });
6379
+ createBaseInputClass({ componentName: componentName$15, baseSelector: 'div' });
6156
6380
 
6157
6381
  const booleanFieldMixin = (superclass) =>
6158
6382
  class BooleanFieldMixinClass extends superclass {
@@ -6161,14 +6385,14 @@ const booleanFieldMixin = (superclass) =>
6161
6385
 
6162
6386
  const template = document.createElement('template');
6163
6387
  template.innerHTML = `
6164
- <${componentName$16}
6388
+ <${componentName$15}
6165
6389
  tabindex="-1"
6166
6390
  slot="input"
6167
- ></${componentName$16}>
6391
+ ></${componentName$15}>
6168
6392
  `;
6169
6393
 
6170
6394
  this.baseElement.appendChild(template.content.cloneNode(true));
6171
- this.inputElement = this.shadowRoot.querySelector(componentName$16);
6395
+ this.inputElement = this.shadowRoot.querySelector(componentName$15);
6172
6396
  this.checkbox = this.inputElement.querySelector('vaadin-checkbox');
6173
6397
 
6174
6398
  forwardAttrs$1(this, this.inputElement, {
@@ -6188,7 +6412,7 @@ const booleanFieldMixin = (superclass) =>
6188
6412
  }
6189
6413
  };
6190
6414
 
6191
- var commonStyles = `
6415
+ var commonStyles = (cssVarList) => `
6192
6416
  :host {
6193
6417
  display: inline-flex;
6194
6418
  }
@@ -6235,9 +6459,18 @@ descope-boolean-field-internal {
6235
6459
  -webkit-mask-image: none;
6236
6460
  min-height: initial;
6237
6461
  }
6462
+
6463
+ descope-enriched-text[empty] {
6464
+ ${EnrichedTextClass.cssVarList.hostDisplay}: none;
6465
+ }
6466
+
6467
+ descope-enriched-text {
6468
+ ${EnrichedTextClass.cssVarList.hostDirection}: var(${cssVarList.hostDirection});
6469
+ }
6470
+
6238
6471
  `;
6239
6472
 
6240
- const componentName$15 = getComponentName$1('checkbox');
6473
+ const componentName$14 = getComponentName$1('checkbox');
6241
6474
 
6242
6475
  const {
6243
6476
  host: host$s,
@@ -6250,7 +6483,9 @@ const {
6250
6483
  errorMessage: errorMessage$a,
6251
6484
  } = {
6252
6485
  host: { selector: () => ':host' },
6253
- requiredIndicator: { selector: '[required] vaadin-checkbox [slot="label"]:not(:empty)::after' },
6486
+ requiredIndicator: {
6487
+ selector: '[required] vaadin-checkbox [slot="label"]:not(:empty)::part(content)::after',
6488
+ },
6254
6489
  component: { selector: 'vaadin-checkbox' },
6255
6490
  checkboxElement: { selector: 'vaadin-checkbox::part(checkbox)' },
6256
6491
  checkboxSurface: { selector: 'vaadin-checkbox::part(checkbox)::after' },
@@ -6296,6 +6531,16 @@ const CheckboxClass = compose$1(
6296
6531
  inputOutlineColor: { ...checkboxElement, property: 'outline-color' },
6297
6532
  inputOutlineStyle: { ...checkboxElement, property: 'outline-style' },
6298
6533
 
6534
+ inputContainerPadding: { ...component$1, property: 'padding' },
6535
+ inputContainerBorderRadius: { ...component$1, property: 'border-radius' },
6536
+ inputContainerBorderWidth: { ...component$1, property: 'border-width' },
6537
+ inputContainerBorderColor: { ...component$1, property: 'border-color' },
6538
+ inputContainerBorderStyle: { ...component$1, property: 'border-style' },
6539
+ inputContainerOutlineWidth: { ...component$1, property: 'outline-width' },
6540
+ inputContainerOutlineOffset: { ...component$1, property: 'outline-offset' },
6541
+ inputContainerOutlineColor: { ...component$1, property: 'outline-color' },
6542
+ inputContainerOutlineStyle: { ...component$1, property: 'outline-style' },
6543
+
6299
6544
  inputSize: [
6300
6545
  { ...checkboxElement, property: 'width' },
6301
6546
  { ...checkboxElement, property: 'height' },
@@ -6313,7 +6558,7 @@ const CheckboxClass = compose$1(
6313
6558
  slots: [],
6314
6559
  wrappedEleName: 'vaadin-text-field',
6315
6560
  style: () => `
6316
- ${commonStyles}
6561
+ ${commonStyles(CheckboxClass.cssVarList)}
6317
6562
  ${useHostExternalPadding(CheckboxClass.cssVarList)}
6318
6563
 
6319
6564
  :host {
@@ -6355,7 +6600,7 @@ const CheckboxClass = compose$1(
6355
6600
  }
6356
6601
  `,
6357
6602
  excludeAttrsSync: ['label', 'tabindex', 'style'],
6358
- componentName: componentName$15,
6603
+ componentName: componentName$14,
6359
6604
  })
6360
6605
  );
6361
6606
 
@@ -6400,7 +6645,7 @@ var checkbox$1 = /*#__PURE__*/Object.freeze({
6400
6645
  vars: vars$X
6401
6646
  });
6402
6647
 
6403
- const componentName$14 = getComponentName$1('switch-toggle');
6648
+ const componentName$13 = getComponentName$1('switch-toggle');
6404
6649
 
6405
6650
  const {
6406
6651
  host: host$r,
@@ -6413,7 +6658,9 @@ const {
6413
6658
  errorMessage: errorMessage$9,
6414
6659
  } = {
6415
6660
  host: { selector: () => ':host' },
6416
- requiredIndicator: { selector: '[required] vaadin-checkbox [slot="label"]:not(:empty)::after' },
6661
+ requiredIndicator: {
6662
+ selector: '[required] vaadin-checkbox [slot="label"]:not(:empty)::part(content)::after',
6663
+ },
6417
6664
  component: { selector: 'vaadin-checkbox' },
6418
6665
  checkboxElement: { selector: 'vaadin-checkbox::part(checkbox)' },
6419
6666
  checkboxSurface: { selector: 'vaadin-checkbox::part(checkbox)::after' },
@@ -6486,7 +6733,7 @@ const SwitchToggleClass = compose$1(
6486
6733
  slots: [],
6487
6734
  wrappedEleName: 'vaadin-text-field',
6488
6735
  style: () => `
6489
- ${commonStyles}
6736
+ ${commonStyles(SwitchToggleClass.cssVarList)}
6490
6737
  ${useHostExternalPadding(SwitchToggleClass.cssVarList)}
6491
6738
 
6492
6739
  :host {
@@ -6542,7 +6789,7 @@ const SwitchToggleClass = compose$1(
6542
6789
  }
6543
6790
  `,
6544
6791
  excludeAttrsSync: ['label', 'tabindex', 'style'],
6545
- componentName: componentName$14,
6792
+ componentName: componentName$13,
6546
6793
  })
6547
6794
  );
6548
6795
 
@@ -6623,9 +6870,9 @@ var switchToggle$1 = /*#__PURE__*/Object.freeze({
6623
6870
  vars: vars$W
6624
6871
  });
6625
6872
 
6626
- const componentName$13 = getComponentName$1('container');
6873
+ const componentName$12 = getComponentName$1('container');
6627
6874
 
6628
- class RawContainer extends createBaseClass({ componentName: componentName$13, baseSelector: 'slot' }) {
6875
+ class RawContainer extends createBaseClass({ componentName: componentName$12, baseSelector: 'slot' }) {
6629
6876
  constructor() {
6630
6877
  super();
6631
6878
 
@@ -6710,7 +6957,7 @@ const [helperTheme$4, helperRefs$4, helperVars$4] = createHelperVars(
6710
6957
  horizontalAlignment,
6711
6958
  shadowColor: '#00000020', // if we want to support transparency vars, we should use different color format
6712
6959
  },
6713
- componentName$13
6960
+ componentName$12
6714
6961
  );
6715
6962
 
6716
6963
  const { shadowColor: shadowColor$4 } = helperRefs$4;
@@ -6875,10 +7122,10 @@ const createCssVarImageClass = ({ componentName, varName, fallbackVarName }) =>
6875
7122
  return CssVarImageClass;
6876
7123
  };
6877
7124
 
6878
- const componentName$12 = getComponentName$1('logo');
7125
+ const componentName$11 = getComponentName$1('logo');
6879
7126
 
6880
7127
  const LogoClass = createCssVarImageClass({
6881
- componentName: componentName$12,
7128
+ componentName: componentName$11,
6882
7129
  varName: 'url',
6883
7130
  fallbackVarName: 'fallbackUrl',
6884
7131
  });
@@ -6895,10 +7142,10 @@ var logo$3 = /*#__PURE__*/Object.freeze({
6895
7142
  vars: vars$U
6896
7143
  });
6897
7144
 
6898
- const componentName$11 = getComponentName$1('totp-image');
7145
+ const componentName$10 = getComponentName$1('totp-image');
6899
7146
 
6900
7147
  const TotpImageClass = createCssVarImageClass({
6901
- componentName: componentName$11,
7148
+ componentName: componentName$10,
6902
7149
  varName: 'url',
6903
7150
  fallbackVarName: 'fallbackUrl',
6904
7151
  });
@@ -6915,10 +7162,10 @@ var totpImage = /*#__PURE__*/Object.freeze({
6915
7162
  vars: vars$T
6916
7163
  });
6917
7164
 
6918
- const componentName$10 = getComponentName$1('notp-image');
7165
+ const componentName$$ = getComponentName$1('notp-image');
6919
7166
 
6920
7167
  const NotpImageClass = createCssVarImageClass({
6921
- componentName: componentName$10,
7168
+ componentName: componentName$$,
6922
7169
  varName: 'url',
6923
7170
  fallbackVarName: 'fallbackUrl',
6924
7171
  });
@@ -6935,10 +7182,10 @@ var notpImage = /*#__PURE__*/Object.freeze({
6935
7182
  vars: vars$S
6936
7183
  });
6937
7184
 
6938
- const componentName$$ = getComponentName('text');
7185
+ const componentName$_ = getComponentName('text');
6939
7186
 
6940
7187
  class RawText extends createBaseClass$1({
6941
- componentName: componentName$$,
7188
+ componentName: componentName$_,
6942
7189
  baseSelector: ':host > slot',
6943
7190
  }) {
6944
7191
  constructor() {
@@ -7010,7 +7257,7 @@ const vars$R = TextClass.cssVarList;
7010
7257
  const text$3 = {
7011
7258
  [vars$R.hostDirection]: globalRefs$A.direction,
7012
7259
  [vars$R.textLineHeight]: '1.35em',
7013
- [vars$R.textAlign]: 'left',
7260
+ [vars$R.textAlign]: 'start',
7014
7261
  [vars$R.textColor]: globalRefs$A.colors.surface.dark,
7015
7262
 
7016
7263
  variant: {
@@ -7107,229 +7354,6 @@ var text$4 = /*#__PURE__*/Object.freeze({
7107
7354
  vars: vars$R
7108
7355
  });
7109
7356
 
7110
- const disableRules = [
7111
- 'blockquote',
7112
- 'list',
7113
- 'image',
7114
- 'table',
7115
- 'code',
7116
- 'hr',
7117
- 'backticks',
7118
- 'fence',
7119
- 'reference',
7120
- 'heading',
7121
- 'lheading',
7122
- 'html_block',
7123
- ];
7124
-
7125
- const decodeHTML = (html) => {
7126
- const textArea = document.createElement('textarea');
7127
- textArea.innerHTML = html;
7128
- return textArea.value;
7129
- };
7130
-
7131
- /* eslint-disable no-param-reassign */
7132
-
7133
-
7134
- const componentName$_ = getComponentName('enriched-text');
7135
-
7136
- class EnrichedText extends createBaseClass$1({ componentName: componentName$_, baseSelector: ':host > div' }) {
7137
- #origLinkRenderer;
7138
-
7139
- #origEmRenderer;
7140
-
7141
- constructor() {
7142
- super();
7143
-
7144
- this.attachShadow({ mode: 'open' }).innerHTML = `
7145
- <div class="content"></div>
7146
- `;
7147
-
7148
- injectStyle(
7149
- `
7150
- :host {
7151
- line-height: 1em;
7152
- word-break: break-word;
7153
- }
7154
- :host > slot {
7155
- width: 100%;
7156
- display: inline-block;
7157
- }
7158
- *, *:last-child {
7159
- margin: 0;
7160
- }
7161
- h1,
7162
- h2,
7163
- h3,
7164
- h4,
7165
- h5,
7166
- h6,
7167
- p {
7168
- margin-bottom: 1em;
7169
- }
7170
- a {
7171
- cursor: pointer;
7172
- }
7173
- blockquote {
7174
- padding: 0 2em;
7175
- }
7176
- u {
7177
- text-decoration: underline
7178
- }
7179
- s {
7180
- color: currentColor;
7181
- }
7182
- `,
7183
- this
7184
- );
7185
-
7186
- this.#initProcessor();
7187
-
7188
- observeChildren(this, this.#parseChildren.bind(this));
7189
- }
7190
-
7191
- static get observedAttributes() {
7192
- return ['readonly', 'link-target-blank'];
7193
- }
7194
-
7195
- attributeChangedCallback(attrName, oldValue, newValue) {
7196
- super.attributeChangedCallback?.(attrName, oldValue, newValue);
7197
-
7198
- if (newValue !== oldValue) {
7199
- if (attrName === 'readonly') {
7200
- this.onReadOnlyChange(newValue === 'true');
7201
- }
7202
-
7203
- if (attrName === 'link-target-blank') {
7204
- this.#initProcessor();
7205
- }
7206
- }
7207
- }
7208
-
7209
- // We're overriding the rule for em with single underscore to perform as underline. (_underline_)
7210
- customUnderlineRenderer() {
7211
- this.processor.renderer.rules.em_open = (tokens, idx, options, env, self) => {
7212
- if (tokens[idx].markup === '_') tokens[idx].tag = 'u';
7213
- return this.#origEmRenderer(tokens, idx, options, env, self);
7214
- };
7215
- this.processor.renderer.rules.em_close = (tokens, idx, options, env, self) => {
7216
- if (tokens[idx].markup === '_') tokens[idx].tag = 'u';
7217
- return this.#origEmRenderer(tokens, idx, options, env, self);
7218
- };
7219
- }
7220
-
7221
- #customizeLinkRenderer() {
7222
- if (this.linkTargetBlank) {
7223
- this.processor.renderer.rules.link_open = (tokens, idx, options, env, self) => {
7224
- // Add a new `target` attribute, or replace the value of the existing one.
7225
- tokens[idx].attrSet('target', '_blank');
7226
- // Pass the token to the default renderer.
7227
- return this.#origLinkRenderer(tokens, idx, options, env, self);
7228
- };
7229
- } else {
7230
- this.processor.renderer.rules.link_open = this.#origLinkRenderer;
7231
- }
7232
- }
7233
-
7234
- #disableCustomRules() {
7235
- if (!this.processor) {
7236
- return;
7237
- }
7238
- this.processor.disable(disableRules);
7239
- }
7240
-
7241
- #updateProcessorRules() {
7242
- this.#disableCustomRules();
7243
- }
7244
-
7245
- #storeOrigRenderers() {
7246
- const defaultLinkRenderer = (tokens, idx, options, _, self) =>
7247
- self.renderToken(tokens, idx, options);
7248
- this.#origLinkRenderer = this.processor.renderer.rules.link_open || defaultLinkRenderer;
7249
-
7250
- const defaultStrongRenderer = (tokens, idx, options, _, self) =>
7251
- self.renderToken(tokens, idx, options);
7252
- this.#origEmRenderer = this.processor.renderer.rules.em_open || defaultStrongRenderer;
7253
- }
7254
-
7255
- #initProcessor() {
7256
- this.processor = new MarkdownIt('commonmark', { html: true });
7257
- this.#storeOrigRenderers();
7258
- this.#updateProcessorRules();
7259
- this.#customizeLinkRenderer();
7260
- this.customUnderlineRenderer();
7261
- }
7262
-
7263
- get linkTargetBlank() {
7264
- return this.getAttribute('link-target-blank') === 'true';
7265
- }
7266
-
7267
- get contentNode() {
7268
- return this.shadowRoot.querySelector('.content');
7269
- }
7270
-
7271
- #parseChildren() {
7272
- if (!this.processor) {
7273
- return;
7274
- }
7275
-
7276
- let html = decodeHTML(this.innerHTML);
7277
-
7278
- if (!html?.trim() && this.isConnected) {
7279
- this.setAttribute('empty', 'true');
7280
- } else {
7281
- this.removeAttribute('empty');
7282
- }
7283
-
7284
- try {
7285
- const tokens = this.processor.parse(html, { references: undefined });
7286
- html = this.processor.renderer.render(tokens, { html: true, breaks: true });
7287
- } catch (e) {
7288
- // eslint-disable-next-line no-console
7289
- console.warn('Not parsing invalid markdown token');
7290
- }
7291
-
7292
- this.contentNode.innerHTML = html;
7293
- }
7294
-
7295
- onReadOnlyChange(isReadOnly) {
7296
- if (isReadOnly) {
7297
- this.contentNode.setAttribute('inert', isReadOnly);
7298
- } else {
7299
- this.contentNode.removeAttribute('inert');
7300
- }
7301
- }
7302
- }
7303
-
7304
- const EnrichedTextClass = compose(
7305
- createStyleMixin$1({
7306
- mappings: {
7307
- hostWidth: { selector: () => ':host', property: 'width' },
7308
- hostDisplay: { selector: () => ':host', property: 'display', fallback: 'inline-block' },
7309
- hostDirection: { selector: () => ':host', property: 'direction' },
7310
- fontSize: {},
7311
- fontFamily: {},
7312
- fontWeight: {},
7313
- fontWeightBold: [
7314
- { selector: () => ':host strong', property: 'font-weight' },
7315
- { selector: () => ':host b', property: 'font-weight' },
7316
- ],
7317
- textColor: { property: 'color' },
7318
- textLineHeight: { property: 'line-height' },
7319
- textAlign: {},
7320
- linkColor: { selector: 'a', property: 'color' },
7321
- linkTextDecoration: { selector: 'a', property: 'text-decoration' },
7322
- linkHoverTextDecoration: { selector: 'a:hover', property: 'text-decoration' },
7323
- minHeight: {},
7324
- minWidth: {},
7325
- },
7326
- }),
7327
- createStyleMixin$1({ componentNameOverride: getComponentName('link') }),
7328
- createStyleMixin$1({ componentNameOverride: getComponentName('text') }),
7329
- draggableMixin$1,
7330
- componentNameValidationMixin$1
7331
- )(EnrichedText);
7332
-
7333
7357
  const componentName$Z = getComponentName('link');
7334
7358
 
7335
7359
  class RawLink extends createBaseClass$1({ componentName: componentName$Z, baseSelector: ':host a' }) {