@brightspace-ui/core 2.44.1 → 2.45.1

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.
@@ -527,6 +527,131 @@
527
527
  </template>
528
528
  </d2l-demo-snippet>
529
529
 
530
+ <h2>HTML Block (html prop)</h2>
531
+
532
+ <d2l-demo-snippet>
533
+ <template>
534
+ <d2l-html-block html="&lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34; display=&#34;block&#34;&gt;&lt;mi&gt;x&lt;/mi&gt;
535
+ &lt;mo&gt;=&lt;/mo&gt;
536
+ &lt;mrow&gt;
537
+ &lt;mfrac&gt;
538
+ &lt;mrow&gt;
539
+ &lt;mo&gt;&amp;#x2212;&lt;/mo&gt;
540
+ &lt;mi&gt;b&lt;/mi&gt;
541
+ &lt;mo&gt;&amp;#xB1;&lt;/mo&gt;
542
+ &lt;msqrt&gt;
543
+ &lt;msup&gt;
544
+ &lt;mi&gt;b&lt;/mi&gt;
545
+ &lt;mn&gt;2&lt;/mn&gt;
546
+ &lt;/msup&gt;
547
+ &lt;mo&gt;&amp;#x2212;&lt;/mo&gt;
548
+ &lt;mn&gt;4&lt;/mn&gt;
549
+ &lt;mi&gt;a&lt;/mi&gt;
550
+ &lt;mi&gt;c&lt;/mi&gt;
551
+ &lt;/msqrt&gt;
552
+ &lt;/mrow&gt;
553
+ &lt;mrow&gt;
554
+ &lt;mn&gt;2&lt;/mn&gt;
555
+ &lt;mi&gt;a&lt;/mi&gt;
556
+ &lt;/mrow&gt;
557
+ &lt;/mfrac&gt;
558
+ &lt;/mrow&gt;
559
+ &lt;mtext&gt;.&lt;/mtext&gt;
560
+ &lt;mspace linebreak=&#34;newline&#34;&gt;&lt;/mspace&gt;
561
+ &lt;msup&gt;
562
+ &lt;mi&gt;e&lt;/mi&gt;
563
+ &lt;mrow&gt;
564
+ &lt;mi&gt;i&lt;/mi&gt;
565
+ &lt;mi&gt;π&lt;!-- π --&gt;&lt;/mi&gt;
566
+ &lt;/mrow&gt;
567
+ &lt;/msup&gt;
568
+ &lt;mo&gt;+&lt;/mo&gt;
569
+ &lt;mn&gt;1&lt;/mn&gt;
570
+ &lt;mo&gt;=&lt;/mo&gt;
571
+ &lt;mn&gt;0&lt;/mn&gt;
572
+ &lt;/math&gt;
573
+ &lt;math xmlns=&#34;http://www.w3.org/1998/Math/MathML&#34; display=&#34;block&#34;&gt;
574
+ &lt;msup&gt;
575
+ &lt;mrow&gt;
576
+ &lt;mo&gt;(&lt;/mo&gt;
577
+ &lt;mrow&gt;
578
+ &lt;munderover&gt;
579
+ &lt;mo&gt;∑&lt;!-- ∑ --&gt;&lt;/mo&gt;
580
+ &lt;mrow class=&#34;MJX-TeXAtom-ORD&#34;&gt;
581
+ &lt;mi&gt;k&lt;/mi&gt;
582
+ &lt;mo&gt;=&lt;/mo&gt;
583
+ &lt;mn&gt;1&lt;/mn&gt;
584
+ &lt;/mrow&gt;
585
+ &lt;mi&gt;n&lt;/mi&gt;
586
+ &lt;/munderover&gt;
587
+ &lt;msub&gt;
588
+ &lt;mi&gt;a&lt;/mi&gt;
589
+ &lt;mi&gt;k&lt;/mi&gt;
590
+ &lt;/msub&gt;
591
+ &lt;msub&gt;
592
+ &lt;mi&gt;b&lt;/mi&gt;
593
+ &lt;mi&gt;k&lt;/mi&gt;
594
+ &lt;/msub&gt;
595
+ &lt;/mrow&gt;
596
+ &lt;mo&gt;)&lt;/mo&gt;
597
+ &lt;/mrow&gt;
598
+ &lt;mrow class=&#34;MJX-TeXAtom-ORD&#34;&gt;
599
+ &lt;mspace width=&#34;negativethinmathspace&#34;&gt;&lt;/mspace&gt;
600
+ &lt;mspace width=&#34;negativethinmathspace&#34;&gt;&lt;/mspace&gt;
601
+ &lt;mn&gt;2&lt;/mn&gt;
602
+ &lt;/mrow&gt;
603
+ &lt;/msup&gt;
604
+ &lt;mo&gt;≤&lt;!-- ≤ --&gt;&lt;/mo&gt;
605
+ &lt;mrow&gt;
606
+ &lt;mo&gt;(&lt;/mo&gt;
607
+ &lt;mrow&gt;
608
+ &lt;munderover&gt;
609
+ &lt;mo&gt;∑&lt;!-- ∑ --&gt;&lt;/mo&gt;
610
+ &lt;mrow class=&#34;MJX-TeXAtom-ORD&#34;&gt;
611
+ &lt;mi&gt;k&lt;/mi&gt;
612
+ &lt;mo&gt;=&lt;/mo&gt;
613
+ &lt;mn&gt;1&lt;/mn&gt;
614
+ &lt;/mrow&gt;
615
+ &lt;mi&gt;n&lt;/mi&gt;
616
+ &lt;/munderover&gt;
617
+ &lt;msubsup&gt;
618
+ &lt;mi&gt;a&lt;/mi&gt;
619
+ &lt;mi&gt;k&lt;/mi&gt;
620
+ &lt;mn&gt;2&lt;/mn&gt;
621
+ &lt;/msubsup&gt;
622
+ &lt;/mrow&gt;
623
+ &lt;mo&gt;)&lt;/mo&gt;
624
+ &lt;/mrow&gt;
625
+ &lt;mrow&gt;
626
+ &lt;mo&gt;(&lt;/mo&gt;
627
+ &lt;mrow&gt;
628
+ &lt;munderover&gt;
629
+ &lt;mo&gt;∑&lt;!-- ∑ --&gt;&lt;/mo&gt;
630
+ &lt;mrow class=&#34;MJX-TeXAtom-ORD&#34;&gt;
631
+ &lt;mi&gt;k&lt;/mi&gt;
632
+ &lt;mo&gt;=&lt;/mo&gt;
633
+ &lt;mn&gt;1&lt;/mn&gt;
634
+ &lt;/mrow&gt;
635
+ &lt;mi&gt;n&lt;/mi&gt;
636
+ &lt;/munderover&gt;
637
+ &lt;msubsup&gt;
638
+ &lt;mi&gt;b&lt;/mi&gt;
639
+ &lt;mi&gt;k&lt;/mi&gt;
640
+ &lt;mn&gt;2&lt;/mn&gt;
641
+ &lt;/msubsup&gt;
642
+ &lt;/mrow&gt;
643
+ &lt;mo&gt;)&lt;/mo&gt;
644
+ &lt;/mrow&gt;
645
+ &lt;/math&gt;
646
+ &lt;div&gt;$$ {\color{red}x} + {\color{blue}y} = {\color{green}z} $$&lt;/div&gt;
647
+ &lt;pre class=&#34;d2l-code d2l-code-dark&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;function helloGrumpy(name) {
648
+ console.log(`Hi there ${name}.`);
649
+ }
650
+ helloGrumpy('Wizard');&lt;/code&gt;&lt;/pre&gt;">
651
+ </d2l-html-block>
652
+ </template>
653
+ </d2l-demo-snippet>
654
+
530
655
  <h2>HTML Block (wrapped)</h2>
531
656
 
532
657
  <d2l-demo-snippet>
@@ -139,6 +139,11 @@ class HtmlBlock extends RtlMixin(LitElement) {
139
139
  * @type {Boolean}
140
140
  */
141
141
  compact: { type: Boolean },
142
+ /**
143
+ * The HTML to be rendered. Ignored if slotted content is provided.
144
+ * @type {String}
145
+ */
146
+ html: { type: String },
142
147
  /**
143
148
  * Whether to display the HTML in inline mode
144
149
  * @type {Boolean}
@@ -183,8 +188,10 @@ class HtmlBlock extends RtlMixin(LitElement) {
183
188
  constructor() {
184
189
  super();
185
190
  this.compact = false;
191
+ this.html = '';
186
192
  this.inline = false;
187
193
  this.noDeferredRendering = false;
194
+ this._hasSlottedContent = false;
188
195
 
189
196
  const rendererContextAttributes = getRenderers().reduce((attrs, currentRenderer) => {
190
197
  if (currentRenderer.contextAttributes) currentRenderer.contextAttributes.forEach(attr => attrs.push(attr));
@@ -202,7 +209,10 @@ class HtmlBlock extends RtlMixin(LitElement) {
202
209
 
203
210
  const slot = this.shadowRoot.querySelector('slot');
204
211
  if (slot) {
205
- slot.assignedNodes({ flatten: true }).forEach(
212
+ const slottedNodes = slot.assignedNodes({ flatten: true });
213
+ this._hasSlottedContent = this._hasSlottedElements(slottedNodes);
214
+
215
+ slottedNodes.forEach(
206
216
  node => this._contentObserver.observe(node, { attributes: true, childList: true, subtree: true })
207
217
  );
208
218
  }
@@ -230,10 +240,17 @@ class HtmlBlock extends RtlMixin(LitElement) {
230
240
  `;
231
241
  }
232
242
 
233
- updated(changedProperties) {
243
+ async updated(changedProperties) {
234
244
  super.updated(changedProperties);
245
+ if (changedProperties.has('html') && this.html !== undefined && this.html !== null && !this._hasSlottedContent) {
246
+ await this._updateRenderContainer();
247
+ }
235
248
  if (this._contextChanged()) {
236
- this._render();
249
+ if (this._hasSlottedContent) this._render();
250
+ else if (this.html !== undefined && this.html !== null) {
251
+ await this._updateRenderContainer();
252
+ }
253
+
237
254
  this._updateContextKeys();
238
255
  }
239
256
  }
@@ -250,8 +267,22 @@ class HtmlBlock extends RtlMixin(LitElement) {
250
267
  }
251
268
 
252
269
  async _handleSlotChange(e) {
253
- if (!e.target) return;
254
- await this._render(e.target);
270
+ if (!e.target || !this.shadowRoot) return;
271
+ const slot = this.shadowRoot.querySelector('slot');
272
+ const slottedNodes = slot.assignedNodes({ flatten: true });
273
+
274
+ if (!this.html && this._hasSlottedElements(slottedNodes)) {
275
+ this._hasSlottedContent = true;
276
+ await this._render(e.target);
277
+ } else {
278
+ this._hasSlottedContent = false;
279
+ }
280
+ }
281
+
282
+ _hasSlottedElements(slottedNodes) {
283
+ if (!slottedNodes || slottedNodes.length === 0) return false;
284
+ if (slottedNodes.filter(node => node.nodeType === Node.ELEMENT_NODE || node.textContent).length === 0) return false;
285
+ return true;
255
286
  }
256
287
 
257
288
  async _processRenderers(elem) {
@@ -322,6 +353,12 @@ class HtmlBlock extends RtlMixin(LitElement) {
322
353
  });
323
354
  }
324
355
 
356
+ async _updateRenderContainer() {
357
+ const renderContainer = this.shadowRoot.querySelector('.d2l-html-block-rendered');
358
+ renderContainer.innerHTML = this.html;
359
+ await this._processRenderers(renderContainer);
360
+ }
361
+
325
362
  }
326
363
 
327
364
  customElements.define('d2l-html-block', HtmlBlock);
@@ -14,13 +14,6 @@
14
14
  import '../tooltip-help.js';
15
15
  </script>
16
16
  <style>
17
- p {
18
- padding-top: 1rem;
19
- }
20
-
21
- p:nth-child(3) {
22
- padding-top: 0;
23
- }
24
17
 
25
18
  .boundary {
26
19
  background-color: var(--d2l-color-citrine);
@@ -163,7 +156,7 @@
163
156
  <d2l-demo-snippet>
164
157
  <template>
165
158
  <d2l-tooltip-help text="Helpful label">Contents should elaborate on the label (be short and concise)</d2l-tooltip-help>
166
- <p class="d2l-body-small">
159
+ <p class="d2l-body-small" style="padding-top: 20px;">
167
160
  This is some sample text.
168
161
  <d2l-tooltip-help text="Helpful label" inherit-font-style>Contents should elaborate on the label (be short and concise)</d2l-tooltip-help>
169
162
  </p>
@@ -3810,6 +3810,12 @@
3810
3810
  "type": "Boolean",
3811
3811
  "default": "false"
3812
3812
  },
3813
+ {
3814
+ "name": "html",
3815
+ "description": "The HTML to be rendered. Ignored if slotted content is provided.",
3816
+ "type": "String",
3817
+ "default": "\"\""
3818
+ },
3813
3819
  {
3814
3820
  "name": "inline",
3815
3821
  "description": "Whether to display the HTML in inline mode",
@@ -3831,6 +3837,13 @@
3831
3837
  "type": "Boolean",
3832
3838
  "default": "false"
3833
3839
  },
3840
+ {
3841
+ "name": "html",
3842
+ "attribute": "html",
3843
+ "description": "The HTML to be rendered. Ignored if slotted content is provided.",
3844
+ "type": "String",
3845
+ "default": "\"\""
3846
+ },
3834
3847
  {
3835
3848
  "name": "inline",
3836
3849
  "attribute": "inline",
package/helpers/prism.js CHANGED
@@ -1,4 +1,4 @@
1
- import { css, unsafeCSS } from 'lit-element/lit-element.js';
1
+ import { css, unsafeCSS } from 'lit';
2
2
 
3
3
  window.Prism = window.Prism || {};
4
4
  Prism.manual = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "2.44.1",
3
+ "version": "2.45.1",
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",