@brightspace-ui/core 2.46.2 → 2.47.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.
@@ -1,9 +1,9 @@
1
1
  import '../colors/colors.js';
2
- import { codeStyles, HtmlBlockCodeRenderer } from '../../helpers/prism.js';
2
+ import { codeStyles, createHtmlBlockRenderer as createCodeRenderer } from '../../helpers/prism.js';
3
3
  import { css, html, LitElement } from 'lit';
4
4
  import { classMap } from 'lit/directives/class-map.js';
5
+ import { createHtmlBlockRenderer as createMathRenderer } from '../../helpers/mathjax.js';
5
6
  import { HtmlAttributeObserverController } from '../../controllers/attributeObserver/htmlAttributeObserverController.js';
6
- import { HtmlBlockMathRenderer } from '../../helpers/mathjax.js';
7
7
  import { requestInstance } from '../../mixins/provider-mixin.js';
8
8
  import { RtlMixin } from '../../mixins/rtl-mixin.js';
9
9
 
@@ -118,10 +118,11 @@ export const htmlBlockContentStyles = css`
118
118
 
119
119
  let renderers;
120
120
 
121
- const getRenderers = () => {
121
+ const getRenderers = async() => {
122
122
  if (renderers) return renderers;
123
- const tempRenderers = requestInstance(document, 'html-block-renderers');
124
- const defaultRenderers = [ new HtmlBlockMathRenderer(), new HtmlBlockCodeRenderer() ];
123
+ const rendererLoader = requestInstance(document, 'html-block-renderer-loader');
124
+ const tempRenderers = rendererLoader ? await rendererLoader.getRenderers() : undefined;
125
+ const defaultRenderers = [ createMathRenderer(), createCodeRenderer() ];
125
126
  renderers = (tempRenderers ? [ ...defaultRenderers, ...tempRenderers ] : defaultRenderers);
126
127
  return renderers;
127
128
  };
@@ -193,13 +194,12 @@ class HtmlBlock extends RtlMixin(LitElement) {
193
194
  this.noDeferredRendering = false;
194
195
  this._hasSlottedContent = false;
195
196
 
196
- const rendererContextAttributes = getRenderers().reduce((attrs, currentRenderer) => {
197
+ getRenderers().then(renderers => renderers.reduce((attrs, currentRenderer) => {
197
198
  if (currentRenderer.contextAttributes) currentRenderer.contextAttributes.forEach(attr => attrs.push(attr));
198
199
  return attrs;
199
- }, []);
200
-
201
- if (rendererContextAttributes.length === 0) return;
202
- this._contextObserverController = new HtmlAttributeObserverController(this, ...rendererContextAttributes);
200
+ }, [])).then(rendererContextAttributes => {
201
+ this._contextObserverController = new HtmlAttributeObserverController(this, ...rendererContextAttributes);
202
+ });
203
203
  }
204
204
 
205
205
  connectedCallback() {
@@ -257,6 +257,10 @@ class HtmlBlock extends RtlMixin(LitElement) {
257
257
 
258
258
  _contextChanged() {
259
259
  if (!this._contextObserverController) return false;
260
+ if (!this._contextKeys) {
261
+ this._updateContextKeys();
262
+ return true;
263
+ }
260
264
 
261
265
  if (this._contextKeys.size !== this._contextObserverController.values.size) return true;
262
266
  for (const [attr, val] of this._contextKeys) {
@@ -286,7 +290,8 @@ class HtmlBlock extends RtlMixin(LitElement) {
286
290
  }
287
291
 
288
292
  async _processRenderers(elem) {
289
- for (const renderer of getRenderers()) {
293
+ const renderers = await getRenderers();
294
+ for (const renderer of renderers) {
290
295
  if (this._contextObserverController && renderer.contextAttributes) {
291
296
  const contextValues = new Map();
292
297
  renderer.contextAttributes.forEach(attr => contextValues.set(attr, this._contextObserverController.values.get(attr)));
@@ -14,9 +14,9 @@ export class HtmlAttributeObserverController {
14
14
  );
15
15
 
16
16
  this._host = host;
17
- host.addController(this);
18
17
  this._attributes = attributes;
19
18
  this.values = new Map();
19
+ host.addController(this);
20
20
  }
21
21
 
22
22
  hostConnected() {
@@ -33,7 +33,7 @@ const mathjaxFontMappings = new Map([
33
33
  let mathJaxLoaded;
34
34
  let renderingPromise = Promise.resolve();
35
35
 
36
- export class HtmlBlockMathRenderer {
36
+ class HtmlBlockMathRenderer {
37
37
 
38
38
  get contextAttributes() {
39
39
  return [mathjaxContextAttribute];
@@ -77,6 +77,10 @@ export class HtmlBlockMathRenderer {
77
77
 
78
78
  }
79
79
 
80
+ export function createHtmlBlockRenderer() {
81
+ return new HtmlBlockMathRenderer();
82
+ }
83
+
80
84
  export function loadMathJax(mathJaxConfig) {
81
85
 
82
86
  if (mathJaxLoaded) return mathJaxLoaded;
package/helpers/prism.js CHANGED
@@ -452,7 +452,7 @@ export async function formatCodeElement(elem) {
452
452
  Prism.highlightElement(code);
453
453
  }
454
454
 
455
- export class HtmlBlockCodeRenderer {
455
+ class HtmlBlockCodeRenderer {
456
456
 
457
457
  get canRenderInline() {
458
458
  return true;
@@ -471,3 +471,7 @@ export class HtmlBlockCodeRenderer {
471
471
  }
472
472
 
473
473
  }
474
+
475
+ export function createHtmlBlockRenderer() {
476
+ return new HtmlBlockCodeRenderer();
477
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "2.46.2",
3
+ "version": "2.47.0",
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",