@brightspace-ui/core 1.220.1 → 1.220.5

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.
@@ -46,7 +46,7 @@ The `d2l-count-badge` element is a web component to display a number count, depe
46
46
  | `number` | Number, required | The number to display on the badge. Must be a positive integer. |
47
47
  | `size`, default: `small` | String | The size of the badge. Valid options are `"small"` and `"large"`. |
48
48
  | `type`, default: `count` | String | The type of the badge. Valid options are `"notification"` and `"count"`. Notification badges are orange and count badges are grey. |
49
- | `max-digits`, default: `2` when `type="notification"` | Number | Optionally specify a digit limit, after which numbers are truncated. Defaults to two for `"notification"` type and no limit for `"count"` type.
49
+ | `max-digits`, default: `2` when `type="notification"`, `5` when `type="count"` | Number | Optionally specify a digit limit, after which numbers are truncated. Defaults to two for `"notification"` type and five for `"count"` type. Must be between 1-5.
50
50
  | `hide-zero`, default: `false` | Boolean | Optionally choose not to show the count badge when the number is zero. |
51
51
  | `text`, required | String | Descriptive text for the badge which will act as an accessible label and tooltip text when tooltips are enabled. |
52
52
  | `tab-stop`, default: `false` | Boolean | Optionally choose to make the badge a tab stop. |
@@ -88,7 +88,7 @@ The `d2l-count-badge-icon` element is a web component to display a number count,
88
88
  | `icon` | String | Required: [Preset icon key](../icons#preset-icons) (e.g. `tier1:gear`) |
89
89
  | `size`, default: `small` | String | The size of the badge. Valid options are `"small"` and `"large"`. |
90
90
  | `type`, default: `count` | String | The type of the badge. Valid options are `"notification"` and `"count"`. Notification badges are orange and count badges are grey. |
91
- | `max-digits`, default: `2` when `type="notification"` | Number | Optionally specify a digit limit, after which numbers are truncated. Defaults to two for `"notification"` type and no limit for `"count"` type.
91
+ | `max-digits`, default: `2` when `type="notification"`, `5` when `type="count"` | Number | Optionally specify a digit limit, after which numbers are truncated. Defaults to two for `"notification"` type and five for `"count"` type. Must be between 1-5.
92
92
  | `hide-zero`, default: `false` | Boolean | Optionally choose not to show the count badge when the number is zero. |
93
93
  | `text` | String | REQUIRED: Descriptive text for the badge which will act as an accessible label and tooltip text when tooltips are enabled. |
94
94
  | `tab-stop`, default: `false` | Boolean | Optionally choose to make the badge a tab stop. |
@@ -9,6 +9,8 @@ import { RtlMixin } from '../../mixins/rtl-mixin.js';
9
9
  import { SkeletonMixin } from '../skeleton/skeleton-mixin.js';
10
10
  import { styleMap } from 'lit-html/directives/style-map.js';
11
11
 
12
+ const maxBadgeDigits = 5;
13
+
12
14
  export const CountBadgeMixin = superclass => class extends LocalizeCoreElement(SkeletonMixin(RtlMixin(superclass))) {
13
15
 
14
16
  static get properties() {
@@ -47,7 +49,8 @@ export const CountBadgeMixin = superclass => class extends LocalizeCoreElement(S
47
49
  attribute: 'hide-zero'
48
50
  },
49
51
  /**
50
- * Optionally specify a digit limit, after which numbers are truncated. Defaults to two for "notification" type and no limit for "count" type.
52
+ * Optionally specify a digit limit, after which numbers are truncated.
53
+ * Defaults to two for "notification" type and five for "count" type.
51
54
  * @type {number}
52
55
  */
53
56
  maxDigits: {
@@ -156,9 +159,20 @@ export const CountBadgeMixin = superclass => class extends LocalizeCoreElement(S
156
159
 
157
160
  connectedCallback() {
158
161
  super.connectedCallback();
159
- if (!this.maxDigits && this.type === 'notification') {
160
- // default to two digits for notification type
161
- this.maxDigits = 2;
162
+ if (!this.maxDigits) {
163
+ // default to two digits for notification type, 5 for count
164
+ this.maxDigits = this.type === 'notification' ? 2 : maxBadgeDigits;
165
+ } else if (this.maxDigits > maxBadgeDigits) {
166
+ // limit all badges to 5 digits
167
+ this.maxDigits = maxBadgeDigits;
168
+ }
169
+ }
170
+
171
+ updated(changedProperties) {
172
+ super.updated(changedProperties);
173
+ if (changedProperties.get('maxDigits') && this.maxDigits > maxBadgeDigits) {
174
+ // impose a 5 digit maximum to prevent overflows
175
+ this.maxDigits = maxBadgeDigits;
162
176
  }
163
177
  }
164
178
 
@@ -166,15 +180,8 @@ export const CountBadgeMixin = superclass => class extends LocalizeCoreElement(S
166
180
  return this.hasTooltip ? undefined : this._labelId;
167
181
  }
168
182
 
169
- renderCount(numberStyles) {
183
+ getNumberString() {
170
184
  let numberString = `${this.number}`;
171
- const hideNumber = this.hideZero && this.number === 0;
172
- if (!numberStyles || numberStyles.visibility !== 'hidden') {
173
- numberStyles = {
174
- ...numberStyles,
175
- visibility: hideNumber ? 'hidden' : 'visible'
176
- };
177
- }
178
185
  if (this.maxDigits && this.number.toString().length > this.maxDigits) {
179
186
  numberString = `${'9'.repeat(this.maxDigits)}`;
180
187
  numberString = formatNumber(parseInt(numberString));
@@ -183,9 +190,20 @@ export const CountBadgeMixin = superclass => class extends LocalizeCoreElement(S
183
190
  numberString = formatNumber(numberString);
184
191
  }
185
192
 
193
+ return numberString;
194
+ }
195
+
196
+ renderCount(numberStyles) {
197
+ const hideNumber = this.hideZero && this.number === 0;
198
+ if (!numberStyles || numberStyles.visibility !== 'hidden') {
199
+ numberStyles = {
200
+ ...numberStyles,
201
+ visibility: hideNumber ? 'hidden' : 'visible'
202
+ };
203
+ }
186
204
  return html`
187
205
  <div class="d2l-count-badge-number" style=${styleMap(numberStyles)}>
188
- <div aria-hidden="true">${numberString}</div>
206
+ <div aria-hidden="true">${this.getNumberString()}</div>
189
207
  </div>
190
208
  `;
191
209
  }
@@ -283,7 +283,6 @@ export const DialogMixin = superclass => class extends RtlMixin(superclass) {
283
283
  if (!this.opened) return;
284
284
  if (e.keyCode === 27) {
285
285
  // escape (note: prevent native dialog close so we can: animate it; use setDismissible)
286
- e.stopPropagation();
287
286
  e.preventDefault();
288
287
  }
289
288
  }
@@ -126,6 +126,7 @@ If the dropdown is initially empty when it's opened, the dropdown pointer will n
126
126
  | `disabled` | Boolean, default: `false` | Disables the dropdown opener |
127
127
  | `no-auto-open` | Boolean, default: `false` | Prevents the dropdown from automatically on click or on key press |
128
128
  | `open-on-hover` | Boolean, default: `false` | Optionally open dropdown on click or hover action |
129
+ | `h-align` | String | Possible values are undefined (default) or text. If text, aligns the button content to the leading edge of text |
129
130
  <!-- docs: end hidden content -->
130
131
 
131
132
  ### Accessibility Properties
@@ -17,6 +17,13 @@ class DropdownButtonSubtle extends DropdownOpenerMixin(LitElement) {
17
17
  * @type {string}
18
18
  */
19
19
  description: { type: String },
20
+
21
+ /**
22
+ * Aligns the leading edge of text if value is set to "text"
23
+ * @type {'text'|''}
24
+ */
25
+ hAlign: { type: String, reflect: true, attribute: 'h-align' },
26
+
20
27
  /**
21
28
  * REQUIRED: Text for the button
22
29
  * @type {string}
@@ -31,7 +38,7 @@ class DropdownButtonSubtle extends DropdownOpenerMixin(LitElement) {
31
38
 
32
39
  render() {
33
40
  return html`
34
- <d2l-button-subtle description="${ifDefined(this.description)}" text=${this.text} icon="tier1:chevron-down" icon-right ?disabled=${this.disabled}></d2l-button-subtle>
41
+ <d2l-button-subtle description="${ifDefined(this.description)}" h-align="${ifDefined(this.hAlign)}" text=${this.text} icon="tier1:chevron-down" icon-right ?disabled=${this.disabled}></d2l-button-subtle>
35
42
  <slot></slot>
36
43
  `;
37
44
  }
@@ -268,7 +268,7 @@ class Filter extends LocalizeCoreElement(RtlMixin(LitElement)) {
268
268
  @d2l-hierarchical-view-hide-start="${this._handleDimensionHideStart}"
269
269
  @d2l-hierarchical-view-show-complete="${this._handleDimensionShowComplete}"
270
270
  @d2l-hierarchical-view-show-start="${this._handleDimensionShowStart}"
271
- @keyup="${this._handleDimensionHideKeyPress}"
271
+ @keydown="${this._handleDimensionHideKeyDown}"
272
272
  data-key="${dimension.key}">
273
273
  ${dimensionHTML}
274
274
  </d2l-hierarchical-view>
@@ -357,7 +357,7 @@ class Filter extends LocalizeCoreElement(RtlMixin(LitElement)) {
357
357
  `;
358
358
 
359
359
  return html`
360
- <div slot="header" @keyup="${this._handleDimensionHideKeyPress}">
360
+ <div slot="header" @keydown="${this._handleDimensionHideKeyDown}">
361
361
  ${header}
362
362
  ${actions}
363
363
  </div>
@@ -551,7 +551,7 @@ class Filter extends LocalizeCoreElement(RtlMixin(LitElement)) {
551
551
  if (this.shadowRoot) this.shadowRoot.querySelector(`d2l-hierarchical-view[data-key="${this._activeDimensionKey}"]`).hide();
552
552
  }
553
553
 
554
- _handleDimensionHideKeyPress(e) {
554
+ _handleDimensionHideKeyDown(e) {
555
555
  if (this._activeDimensionKey && (e.keyCode === ARROWLEFT_KEY_CODE || e.keyCode === ESCAPE_KEY_CODE)) {
556
556
  e.stopPropagation();
557
557
  this._handleDimensionHide();
@@ -154,7 +154,7 @@ export const HierarchicalViewMixin = superclass => class extends superclass {
154
154
  firstUpdated(changedProperties) {
155
155
  super.firstUpdated(changedProperties);
156
156
 
157
- this.addEventListener('keyup', this.__onKeyUp);
157
+ this.addEventListener('keydown', this.__onKeyDown);
158
158
  this.addEventListener('d2l-hierarchical-view-hide-start', this.__onHideStart);
159
159
  this.addEventListener('d2l-hierarchical-view-show-start', this.__onShowStart);
160
160
  this.addEventListener('d2l-hierarchical-view-resize', this.__onViewResize);
@@ -477,7 +477,7 @@ export const HierarchicalViewMixin = superclass => class extends superclass {
477
477
 
478
478
  }
479
479
 
480
- __onKeyUp(e) {
480
+ __onKeyDown(e) {
481
481
  if (this.childView && e.keyCode === escapeKeyCode) {
482
482
  e.stopPropagation();
483
483
  this.hide();
@@ -177,15 +177,11 @@ class HtmlBlock extends LitElement {
177
177
 
178
178
  if (!this._contentObserver || this.noDeferredRendering) return;
179
179
 
180
- const template = this._findSlottedElement('TEMPLATE');
181
- if (template) this._contentObserver.observe(template.content, { attributes: true, childList: true, subtree: true });
182
- else {
183
- const slot = this.shadowRoot.querySelector('slot');
184
- if (slot) {
185
- slot.assignedNodes({ flatten: true }).forEach(
186
- node => this._contentObserver.observe(node, { attributes: true, childList: true, subtree: true })
187
- );
188
- }
180
+ const slot = this.shadowRoot.querySelector('slot');
181
+ if (slot) {
182
+ slot.assignedNodes({ flatten: true }).forEach(
183
+ node => this._contentObserver.observe(node, { attributes: true, childList: true, subtree: true })
184
+ );
189
185
  }
190
186
  }
191
187
 
@@ -220,13 +216,6 @@ class HtmlBlock extends LitElement {
220
216
  return false;
221
217
  }
222
218
 
223
- _findSlottedElement(tagName, slot) {
224
- if (!this.shadowRoot) return;
225
- if (!slot) slot = this.shadowRoot.querySelector('slot');
226
- return slot.assignedNodes({ flatten: true })
227
- .find(node => (node.nodeType === Node.ELEMENT_NODE && node.tagName === tagName.toUpperCase()));
228
- }
229
-
230
219
  async _processRenderers(elem) {
231
220
  for (const renderer of getRenderers()) {
232
221
  if (this._contextObserverController && renderer.contextAttributes) {
@@ -252,26 +241,23 @@ class HtmlBlock extends LitElement {
252
241
  }
253
242
 
254
243
  async _renderInline(slot) {
255
- const noDeferredRenderingContainer = this._findSlottedElement('DIV', slot);
244
+ if (!this.shadowRoot) return;
245
+ if (!slot) slot = this.shadowRoot.querySelector('slot');
246
+
247
+ const noDeferredRenderingContainer = slot.assignedNodes({ flatten: true })
248
+ .find(node => (node.nodeType === Node.ELEMENT_NODE && node.tagName === 'DIV'));
249
+
256
250
  if (!noDeferredRenderingContainer) return;
257
251
  await this._processRenderers(noDeferredRenderingContainer);
258
252
  }
259
253
 
260
254
  _stamp(slot) {
261
- const stampHTML = async template => {
262
- let fragment;
263
- if (template) fragment = document.importNode(template.content, true);
264
- else {
265
- fragment = document.createDocumentFragment();
266
- this.shadowRoot.querySelector('slot').assignedNodes({ flatten: true })
267
- .forEach(node => fragment.appendChild(node.cloneNode(true)));
268
- }
269
-
270
- if (fragment.hasChildNodes()) {
255
+ const stampHTML = async nodes => {
256
+ if (nodes && nodes.length > 0) {
271
257
 
272
258
  let temp = document.createElement('div');
273
259
  temp.style.display = 'none';
274
- temp.appendChild(fragment);
260
+ nodes.forEach(node => temp.appendChild(node.cloneNode(true)));
275
261
 
276
262
  this._renderContainer.appendChild(temp);
277
263
  temp = await this._processRenderers(temp);
@@ -284,18 +270,15 @@ class HtmlBlock extends LitElement {
284
270
 
285
271
  if (this._contentObserver) this._contentObserver.disconnect();
286
272
 
287
- const template = this._findSlottedElement('TEMPLATE', slot);
288
- if (template) {
289
- this._contentObserver = new MutationObserver(() => stampHTML(template));
290
- this._contentObserver.observe(template.content, { attributes: true, childList: true, subtree: true });
291
- } else {
292
- this._contentObserver = new MutationObserver(() => stampHTML());
293
- this.shadowRoot.querySelector('slot').assignedNodes({ flatten: true }).forEach(
294
- node => this._contentObserver.observe(node, { attributes: true, childList: true, subtree: true })
295
- );
296
- }
273
+ if (!slot) slot = this.shadowRoot.querySelector('slot');
274
+ const slottedNodes = slot.assignedNodes({ flatten: true });
275
+
276
+ this._contentObserver = new MutationObserver(() => stampHTML(slottedNodes));
277
+ slottedNodes.forEach(
278
+ node => this._contentObserver.observe(node, { attributes: true, childList: true, subtree: true })
279
+ );
297
280
 
298
- stampHTML(template);
281
+ stampHTML(slottedNodes);
299
282
  }
300
283
 
301
284
  }
@@ -1032,7 +1032,7 @@
1032
1032
  },
1033
1033
  {
1034
1034
  "name": "max-digits",
1035
- "description": "Optionally specify a digit limit, after which numbers are truncated. Defaults to two for \"notification\" type and no limit for \"count\" type.",
1035
+ "description": "Optionally specify a digit limit, after which numbers are truncated.\nDefaults to two for \"notification\" type and five for \"count\" type.",
1036
1036
  "type": "number"
1037
1037
  },
1038
1038
  {
@@ -1105,7 +1105,7 @@
1105
1105
  {
1106
1106
  "name": "maxDigits",
1107
1107
  "attribute": "max-digits",
1108
- "description": "Optionally specify a digit limit, after which numbers are truncated. Defaults to two for \"notification\" type and no limit for \"count\" type.",
1108
+ "description": "Optionally specify a digit limit, after which numbers are truncated.\nDefaults to two for \"notification\" type and five for \"count\" type.",
1109
1109
  "type": "number"
1110
1110
  },
1111
1111
  {
@@ -1185,7 +1185,7 @@
1185
1185
  "attributes": [
1186
1186
  {
1187
1187
  "name": "max-digits",
1188
- "description": "Optionally specify a digit limit, after which numbers are truncated. Defaults to two for \"notification\" type and no limit for \"count\" type.",
1188
+ "description": "Optionally specify a digit limit, after which numbers are truncated.\nDefaults to two for \"notification\" type and five for \"count\" type.",
1189
1189
  "type": "number"
1190
1190
  },
1191
1191
  {
@@ -1252,7 +1252,7 @@
1252
1252
  {
1253
1253
  "name": "maxDigits",
1254
1254
  "attribute": "max-digits",
1255
- "description": "Optionally specify a digit limit, after which numbers are truncated. Defaults to two for \"notification\" type and no limit for \"count\" type.",
1255
+ "description": "Optionally specify a digit limit, after which numbers are truncated.\nDefaults to two for \"notification\" type and five for \"count\" type.",
1256
1256
  "type": "number"
1257
1257
  },
1258
1258
  {
@@ -1686,6 +1686,11 @@
1686
1686
  "description": "A description to be added to the opener button for accessibility when text on button does not provide enough context",
1687
1687
  "type": "string"
1688
1688
  },
1689
+ {
1690
+ "name": "h-align",
1691
+ "description": "Aligns the leading edge of text if value is set to \"text\"",
1692
+ "type": "'text'|''"
1693
+ },
1689
1694
  {
1690
1695
  "name": "text",
1691
1696
  "description": "REQUIRED: Text for the button",
@@ -1717,6 +1722,12 @@
1717
1722
  "description": "A description to be added to the opener button for accessibility when text on button does not provide enough context",
1718
1723
  "type": "string"
1719
1724
  },
1725
+ {
1726
+ "name": "hAlign",
1727
+ "attribute": "h-align",
1728
+ "description": "Aligns the leading edge of text if value is set to \"text\"",
1729
+ "type": "'text'|''"
1730
+ },
1720
1731
  {
1721
1732
  "name": "text",
1722
1733
  "attribute": "text",
@@ -4,7 +4,7 @@ const stack = [];
4
4
 
5
5
  function cleanup() {
6
6
  if (eventListener && stack.length === 0) {
7
- document.removeEventListener('keyup', eventListener);
7
+ document.removeEventListener('keydown', eventListener);
8
8
  eventListener = null;
9
9
  }
10
10
  }
@@ -23,7 +23,7 @@ function init() {
23
23
  }
24
24
  cleanup();
25
25
  };
26
- document.addEventListener('keyup', eventListener);
26
+ document.addEventListener('keydown', eventListener);
27
27
  }
28
28
 
29
29
  export function clearDismissible(id) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "1.220.1",
3
+ "version": "1.220.5",
4
4
  "description": "A collection of accessible, free, open-source web components for building Brightspace applications",
5
5
  "type": "module",
6
6
  "repository": "https://github.com/BrightspaceUI/core.git",
@@ -1,634 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="en">
3
- <head>
4
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
5
- <meta charset="UTF-8">
6
- <link rel="stylesheet" href="../../demo/styles.css" type="text/css">
7
- <script type="module">
8
- import '../../demo/demo-page.js';
9
- import '../html-block.js';
10
- import { provideInstance } from '../../../mixins/provider-mixin.js';
11
-
12
- class DemoReplacementRenderer {
13
- get canRenderInline() {
14
- return true;
15
- }
16
-
17
- async render(elem) {
18
- const elemsToReplace = elem.querySelectorAll('[data-replace-me-id]');
19
- if (elemsToReplace.length === 0) return elem;
20
-
21
- elemsToReplace.forEach(elemToReplace => {
22
-
23
- const someId = elemToReplace.getAttribute('data-replace-me-id');
24
- if (!someId) return;
25
-
26
- const anchor = document.createElement('a');
27
- anchor.href = `/d2l/lp/some-route?someId=${parseInt(someId)}`;
28
- anchor.target = '_blank';
29
- anchor.innerText = elemToReplace.innerText;
30
-
31
- elemToReplace.innerText = '';
32
- elemToReplace.appendChild(anchor);
33
-
34
- });
35
-
36
- return elem;
37
- }
38
- }
39
-
40
- // demo replacement renderer for html-block
41
- provideInstance(document, 'html-block-renderers', [ new DemoReplacementRenderer() ]);
42
-
43
- </script>
44
- <script>
45
- document.getElementsByTagName('html')[0].dataset.mathjaxContext = JSON.stringify({ outputScale: 1.1, renderLatex: window.location.search.indexOf('latex=true') !== -1 });
46
- </script>
47
- </head>
48
- <body unresolved>
49
-
50
- <d2l-demo-page page-title="d2l-html-block - templates">
51
-
52
- <h2>HTML Block</h2>
53
-
54
- <d2l-demo-snippet>
55
- <template>
56
- <d2l-html-block>
57
- <template>
58
- <h1>heading 1</h1>
59
- <h2>heading 2</h2>
60
- <h3>heading 3</h3>
61
- <h4>heading 4</h4>
62
- <h5>heading 5</h5>
63
- <h6>heading 6</h6>
64
- <div><strong>strong</strong></div>
65
- <div><b>bold</b></div>
66
- <div>text</div>
67
- <pre>preformatted</pre>
68
- <p>paragraph</p>
69
- <ul>
70
- <li>unordered item 1</li>
71
- <li>unordered item 2</li>
72
- </ul>
73
- <ol>
74
- <li>ordered item 1</li>
75
- <li>ordered item 2</li>
76
- </ol>
77
- <div><a href="https://d2l.com">anchor</a></div>
78
- </template>
79
- </d2l-html-block>
80
- </template>
81
- </d2l-demo-snippet>
82
-
83
- <h2>HTML Block (compact)</h2>
84
-
85
- <d2l-demo-snippet>
86
- <template>
87
- <d2l-html-block compact>
88
- <template>
89
- <h1>heading 1</h1>
90
- <h2>heading 2</h2>
91
- <h3>heading 3</h3>
92
- <h4>heading 4</h4>
93
- <h5>heading 5</h5>
94
- <h6>heading 6</h6>
95
- <div><strong>strong</strong></div>
96
- <div><b>bold</b></div>
97
- <div>text</div>
98
- <pre>preformatted</pre>
99
- <p>paragraph</p>
100
- <ul>
101
- <li>unordered item 1</li>
102
- <li>unordered item 2</li>
103
- </ul>
104
- <ol>
105
- <li>ordered item 1</li>
106
- <li>ordered item 2</li>
107
- </ol>
108
- <div><a href="https://d2l.com">anchor</a></div>
109
- </template>
110
- </d2l-html-block>
111
- </template>
112
- </d2l-demo-snippet>
113
-
114
- <h2>HTML Block (math)</h2>
115
-
116
- <d2l-demo-snippet>
117
- <template>
118
- <d2l-html-block>
119
- <template>
120
- <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
121
- <mi>x</mi>
122
- <mo>=</mo>
123
- <mrow>
124
- <mfrac>
125
- <mrow>
126
- <mo>&#x2212;</mo>
127
- <mi>b</mi>
128
- <mo>&#xB1;</mo>
129
- <msqrt>
130
- <msup>
131
- <mi>b</mi>
132
- <mn>2</mn>
133
- </msup>
134
- <mo>&#x2212;</mo>
135
- <mn>4</mn>
136
- <mi>a</mi>
137
- <mi>c</mi>
138
- </msqrt>
139
- </mrow>
140
- <mrow>
141
- <mn>2</mn>
142
- <mi>a</mi>
143
- </mrow>
144
- </mfrac>
145
- </mrow>
146
- <mtext>.</mtext>
147
- </math>
148
- <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
149
- <msup>
150
- <mrow>
151
- <mo>(</mo>
152
- <mrow>
153
- <munderover>
154
- <mo>∑<!-- ∑ --></mo>
155
- <mrow class="MJX-TeXAtom-ORD">
156
- <mi>k</mi>
157
- <mo>=</mo>
158
- <mn>1</mn>
159
- </mrow>
160
- <mi>n</mi>
161
- </munderover>
162
- <msub>
163
- <mi>a</mi>
164
- <mi>k</mi>
165
- </msub>
166
- <msub>
167
- <mi>b</mi>
168
- <mi>k</mi>
169
- </msub>
170
- </mrow>
171
- <mo>)</mo>
172
- </mrow>
173
- <mrow class="MJX-TeXAtom-ORD">
174
- <mspace width="negativethinmathspace"></mspace>
175
- <mspace width="negativethinmathspace"></mspace>
176
- <mn>2</mn>
177
- </mrow>
178
- </msup>
179
- <mo>≤<!-- ≤ --></mo>
180
- <mrow>
181
- <mo>(</mo>
182
- <mrow>
183
- <munderover>
184
- <mo>∑<!-- ∑ --></mo>
185
- <mrow class="MJX-TeXAtom-ORD">
186
- <mi>k</mi>
187
- <mo>=</mo>
188
- <mn>1</mn>
189
- </mrow>
190
- <mi>n</mi>
191
- </munderover>
192
- <msubsup>
193
- <mi>a</mi>
194
- <mi>k</mi>
195
- <mn>2</mn>
196
- </msubsup>
197
- </mrow>
198
- <mo>)</mo>
199
- </mrow>
200
- <mrow>
201
- <mo>(</mo>
202
- <mrow>
203
- <munderover>
204
- <mo>∑<!-- ∑ --></mo>
205
- <mrow class="MJX-TeXAtom-ORD">
206
- <mi>k</mi>
207
- <mo>=</mo>
208
- <mn>1</mn>
209
- </mrow>
210
- <mi>n</mi>
211
- </munderover>
212
- <msubsup>
213
- <mi>b</mi>
214
- <mi>k</mi>
215
- <mn>2</mn>
216
- </msubsup>
217
- </mrow>
218
- <mo>)</mo>
219
- </mrow>
220
- </math>
221
- </template>
222
- </d2l-html-block>
223
- </template>
224
- </d2l-demo-snippet>
225
-
226
- <h2>HTML Block (math, no deferred rendering)</h2>
227
-
228
- <d2l-demo-snippet>
229
- <template>
230
- <d2l-html-block no-deferred-rendering>
231
- <div>
232
- <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
233
- <mi>x</mi>
234
- <mo>=</mo>
235
- <mrow>
236
- <mfrac>
237
- <mrow>
238
- <mo>&#x2212;</mo>
239
- <mi>b</mi>
240
- <mo>&#xB1;</mo>
241
- <msqrt>
242
- <msup>
243
- <mi>b</mi>
244
- <mn>2</mn>
245
- </msup>
246
- <mo>&#x2212;</mo>
247
- <mn>4</mn>
248
- <mi>a</mi>
249
- <mi>c</mi>
250
- </msqrt>
251
- </mrow>
252
- <mrow>
253
- <mn>2</mn>
254
- <mi>a</mi>
255
- </mrow>
256
- </mfrac>
257
- </mrow>
258
- <mtext>.</mtext>
259
- </math>
260
- <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
261
- <msup>
262
- <mrow>
263
- <mo>(</mo>
264
- <mrow>
265
- <munderover>
266
- <mo>∑<!-- ∑ --></mo>
267
- <mrow class="MJX-TeXAtom-ORD">
268
- <mi>k</mi>
269
- <mo>=</mo>
270
- <mn>1</mn>
271
- </mrow>
272
- <mi>n</mi>
273
- </munderover>
274
- <msub>
275
- <mi>a</mi>
276
- <mi>k</mi>
277
- </msub>
278
- <msub>
279
- <mi>b</mi>
280
- <mi>k</mi>
281
- </msub>
282
- </mrow>
283
- <mo>)</mo>
284
- </mrow>
285
- <mrow class="MJX-TeXAtom-ORD">
286
- <mspace width="negativethinmathspace"></mspace>
287
- <mspace width="negativethinmathspace"></mspace>
288
- <mn>2</mn>
289
- </mrow>
290
- </msup>
291
- <mo>≤<!-- ≤ --></mo>
292
- <mrow>
293
- <mo>(</mo>
294
- <mrow>
295
- <munderover>
296
- <mo>∑<!-- ∑ --></mo>
297
- <mrow class="MJX-TeXAtom-ORD">
298
- <mi>k</mi>
299
- <mo>=</mo>
300
- <mn>1</mn>
301
- </mrow>
302
- <mi>n</mi>
303
- </munderover>
304
- <msubsup>
305
- <mi>a</mi>
306
- <mi>k</mi>
307
- <mn>2</mn>
308
- </msubsup>
309
- </mrow>
310
- <mo>)</mo>
311
- </mrow>
312
- <mrow>
313
- <mo>(</mo>
314
- <mrow>
315
- <munderover>
316
- <mo>∑<!-- ∑ --></mo>
317
- <mrow class="MJX-TeXAtom-ORD">
318
- <mi>k</mi>
319
- <mo>=</mo>
320
- <mn>1</mn>
321
- </mrow>
322
- <mi>n</mi>
323
- </munderover>
324
- <msubsup>
325
- <mi>b</mi>
326
- <mi>k</mi>
327
- <mn>2</mn>
328
- </msubsup>
329
- </mrow>
330
- <mo>)</mo>
331
- </mrow>
332
- </math>
333
- <p>The wizard (<span data-replace-me-id="0">Elmer Fudd</span>) quickly jinxed the gnomes before they vaporized.</p>
334
- </div>
335
- </d2l-html-block>
336
- </template>
337
- </d2l-demo-snippet>
338
-
339
- <h2>HTML Block (inline math)</h2>
340
-
341
- <d2l-demo-snippet>
342
- <template>
343
- <d2l-html-block>
344
- <template>
345
- <div>An equation...
346
- <math xmlns="http://www.w3.org/1998/Math/MathML">
347
- <msqrt>
348
- <mn>3</mn>
349
- <mi>x</mi>
350
- <mo>&#x2212;</mo>
351
- <mn>1</mn>
352
- </msqrt>
353
- <mo>+</mo>
354
- <mo stretchy="false">(</mo>
355
- <mn>1</mn>
356
- <mo>+</mo>
357
- <mi>x</mi>
358
- <msup>
359
- <mo stretchy="false">)</mo>
360
- <mn>2</mn>
361
- </msup>
362
- </math> embedded inline with text... and showing placement of indicies for summations
363
- <math xmlns="http://www.w3.org/1998/Math/MathML">
364
- <msup>
365
- <mrow>
366
- <mo>(</mo>
367
- <mrow>
368
- <munderover>
369
- <mo>∑<!-- ∑ --></mo>
370
- <mrow class="MJX-TeXAtom-ORD">
371
- <mi>k</mi>
372
- <mo>=</mo>
373
- <mn>1</mn>
374
- </mrow>
375
- <mi>n</mi>
376
- </munderover>
377
- <msub>
378
- <mi>a</mi>
379
- <mi>k</mi>
380
- </msub>
381
- <msub>
382
- <mi>b</mi>
383
- <mi>k</mi>
384
- </msub>
385
- </mrow>
386
- <mo>)</mo>
387
- </mrow>
388
- <mrow class="MJX-TeXAtom-ORD">
389
- <mspace width="negativethinmathspace"></mspace>
390
- <mspace width="negativethinmathspace"></mspace>
391
- <mn>2</mn>
392
- </mrow>
393
- </msup>
394
- <mo>≤<!-- ≤ --></mo>
395
- <mrow>
396
- <mo>(</mo>
397
- <mrow>
398
- <munderover>
399
- <mo>∑<!-- ∑ --></mo>
400
- <mrow class="MJX-TeXAtom-ORD">
401
- <mi>k</mi>
402
- <mo>=</mo>
403
- <mn>1</mn>
404
- </mrow>
405
- <mi>n</mi>
406
- </munderover>
407
- <msubsup>
408
- <mi>a</mi>
409
- <mi>k</mi>
410
- <mn>2</mn>
411
- </msubsup>
412
- </mrow>
413
- <mo>)</mo>
414
- </mrow>
415
- <mrow>
416
- <mo>(</mo>
417
- <mrow>
418
- <munderover>
419
- <mo>∑<!-- ∑ --></mo>
420
- <mrow class="MJX-TeXAtom-ORD">
421
- <mi>k</mi>
422
- <mo>=</mo>
423
- <mn>1</mn>
424
- </mrow>
425
- <mi>n</mi>
426
- </munderover>
427
- <msubsup>
428
- <mi>b</mi>
429
- <mi>k</mi>
430
- <mn>2</mn>
431
- </msubsup>
432
- </mrow>
433
- <mo>)</mo>
434
- </mrow>
435
- </math> and other symbols.
436
- </div>
437
- </template>
438
- </d2l-html-block>
439
- </template>
440
- </d2l-demo-snippet>
441
-
442
- <h2>HTML Block (LaTeX math)</h2>
443
-
444
- <d2l-demo-snippet>
445
- <template>
446
- <d2l-html-block>
447
- <template>
448
- <div>$$ f(x) = \int \mathrm{e}^{-x}\,\mathrm{d}x $$ $$ x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a} $$</div>
449
- </template>
450
- </d2l-html-block>
451
- </template>
452
- </d2l-demo-snippet>
453
-
454
- <h2>HTML Block (LaTeX inline math)</h2>
455
-
456
- <d2l-demo-snippet>
457
- <template>
458
- <d2l-html-block>
459
- <template>
460
- <div>An equation rendered using LaTeX...
461
- \( f(x) = \int \mathrm{e}^{-x}\,\mathrm{d}x \)
462
- ... and some text!
463
- </div>
464
- </template>
465
- </d2l-html-block>
466
- </template>
467
- </d2l-demo-snippet>
468
-
469
- <h2>HTML Block (wrapped)</h2>
470
-
471
- <d2l-demo-snippet>
472
- <template>
473
- <d2l-some-component></d2l-some-component>
474
- </template>
475
- </d2l-demo-snippet>
476
-
477
- <d2l-code-view language="javascript">
478
- import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';
479
- import { html, LitElement } from 'lit-element/lit-element.js';
480
-
481
- class SomeComponent extends LitElement {
482
-
483
- render() {
484
- return html`
485
- &lt;d2l-html-block&gt;
486
- &lt;template&gt;${unsafeHTML(this._someHTML)}&lt;/template&gt;
487
- &lt;/d2l-html-block&gt;
488
- &lt;button ...&gt;update content&lt;/button&gt;`;
489
- `;
490
- }
491
- }
492
-
493
- customElements.define('d2l-some-component', SomeComponent);
494
- </d2l-code-view>
495
-
496
- </d2l-demo-page>
497
-
498
- <script type="module">
499
- import { html, LitElement } from 'lit-element/lit-element.js';
500
- import { unsafeHTML } from 'lit-html/directives/unsafe-html.js';
501
-
502
- class SomeComponent extends LitElement {
503
-
504
- static get properties() {
505
- return {
506
- _htmlSnippets: { type: Array },
507
- _updateCount: { type: Number }
508
- };
509
- }
510
-
511
- constructor() {
512
- super();
513
- this._htmlSnippets = [
514
- `<div>An equation...
515
- <math xmlns="http://www.w3.org/1998/Math/MathML">
516
- <msqrt>
517
- <mn>3</mn>
518
- <mi>x</mi>
519
- <mo>&#x2212;</mo>
520
- <mn>1</mn>
521
- </msqrt>
522
- <mo>+</mo>
523
- <mo stretchy="false">(</mo>
524
- <mn>1</mn>
525
- <mo>+</mo>
526
- <mi>x</mi>
527
- <msup>
528
- <mo stretchy="false">)</mo>
529
- <mn>2</mn>
530
- </msup>
531
- </math> embedded inline with text... and showing placement of indicies for summations
532
- <math xmlns="http://www.w3.org/1998/Math/MathML">
533
- <msup>
534
- <mrow>
535
- <mo>(</mo>
536
- <mrow>
537
- <munderover>
538
- <mo>∑<!-- ∑ --></mo>
539
- <mrow class="MJX-TeXAtom-ORD">
540
- <mi>k</mi>
541
- <mo>=</mo>
542
- <mn>1</mn>
543
- </mrow>
544
- <mi>n</mi>
545
- </munderover>
546
- <msub>
547
- <mi>a</mi>
548
- <mi>k</mi>
549
- </msub>
550
- <msub>
551
- <mi>b</mi>
552
- <mi>k</mi>
553
- </msub>
554
- </mrow>
555
- <mo>)</mo>
556
- </mrow>
557
- <mrow class="MJX-TeXAtom-ORD">
558
- <mspace width="negativethinmathspace"></mspace>
559
- <mspace width="negativethinmathspace"></mspace>
560
- <mn>2</mn>
561
- </mrow>
562
- </msup>
563
- <mo>≤<!-- ≤ --></mo>
564
- <mrow>
565
- <mo>(</mo>
566
- <mrow>
567
- <munderover>
568
- <mo>∑<!-- ∑ --></mo>
569
- <mrow class="MJX-TeXAtom-ORD">
570
- <mi>k</mi>
571
- <mo>=</mo>
572
- <mn>1</mn>
573
- </mrow>
574
- <mi>n</mi>
575
- </munderover>
576
- <msubsup>
577
- <mi>a</mi>
578
- <mi>k</mi>
579
- <mn>2</mn>
580
- </msubsup>
581
- </mrow>
582
- <mo>)</mo>
583
- </mrow>
584
- <mrow>
585
- <mo>(</mo>
586
- <mrow>
587
- <munderover>
588
- <mo>∑<!-- ∑ --></mo>
589
- <mrow class="MJX-TeXAtom-ORD">
590
- <mi>k</mi>
591
- <mo>=</mo>
592
- <mn>1</mn>
593
- </mrow>
594
- <mi>n</mi>
595
- </munderover>
596
- <msubsup>
597
- <mi>b</mi>
598
- <mi>k</mi>
599
- <mn>2</mn>
600
- </msubsup>
601
- </mrow>
602
- <mo>)</mo>
603
- </mrow>
604
- </math> and other symbols.
605
- </div>`,
606
- 'The wizard quickly jinxed the gnomes before they vaporized.',
607
- 'The wizard (<span data-replace-me-id="0">Elmer Fudd</span>) quickly jinxed the gnomes before they vaporized.',
608
- 'A quick movement of the enemy will jeopardize six gunboats.',
609
- 'Grumpy wizards make a toxic brew for the jovial queen.',
610
- 'Painful zombies quickly watch a jinxed graveyard.',
611
- 'Jackie will budget for the most expensive zoology equipment.',
612
- 'No more updates for you.'
613
- ];
614
- this._updateCount = 0;
615
- }
616
-
617
- render() {
618
- return html`
619
- <d2l-html-block>
620
- <template>${unsafeHTML(this._htmlSnippets[this._updateCount])}</template>
621
- </d2l-html-block>
622
- <button @click="${this._updateTemplateContent}" ?disabled="${this._updateCount === 6}">update content</button>`;
623
- }
624
-
625
- _updateTemplateContent() {
626
- if (this._updateCount < 6) this._updateCount += 1;
627
- }
628
-
629
- }
630
- customElements.define('d2l-some-component', SomeComponent);
631
- </script>
632
-
633
- </body>
634
- </html>