@brightspace-ui/core 3.38.2 → 3.38.3
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,13 +1,14 @@
|
|
1
1
|
import '../colors/colors.js';
|
2
2
|
import { codeStyles, createHtmlBlockRenderer as createCodeRenderer } from '../../helpers/prism.js';
|
3
|
-
import {
|
3
|
+
import { createRef, ref } from 'lit/directives/ref.js';
|
4
|
+
import { css, html, LitElement, unsafeCSS } from 'lit';
|
4
5
|
import { classMap } from 'lit/directives/class-map.js';
|
5
6
|
import { createHtmlBlockRenderer as createMathRenderer } from '../../helpers/mathjax.js';
|
6
7
|
import { getFocusPseudoClass } from '../../helpers/focus.js';
|
8
|
+
import { LoadingCompleteMixin } from '../../mixins/loading-complete/loading-complete-mixin.js';
|
7
9
|
import { renderEmbeds } from '../../helpers/embeds.js';
|
8
10
|
import { requestInstance } from '../../mixins/provider/provider-mixin.js';
|
9
11
|
import { tryGet } from '@brightspace-ui/lms-context-provider/client.js';
|
10
|
-
import { until } from 'lit/directives/until.js';
|
11
12
|
|
12
13
|
export const htmlBlockContentStyles = css`
|
13
14
|
.d2l-html-block-rendered {
|
@@ -142,7 +143,7 @@ const getRenderers = async() => {
|
|
142
143
|
/**
|
143
144
|
* A component for displaying user-authored HTML.
|
144
145
|
*/
|
145
|
-
class HtmlBlock extends LitElement {
|
146
|
+
class HtmlBlock extends LoadingCompleteMixin(LitElement) {
|
146
147
|
|
147
148
|
static get properties() {
|
148
149
|
return {
|
@@ -206,8 +207,7 @@ class HtmlBlock extends LitElement {
|
|
206
207
|
this._initialContextResolve = undefined;
|
207
208
|
this._initialContextPromise = new Promise(resolve => this._initialContextResolve = resolve);
|
208
209
|
|
209
|
-
this.
|
210
|
-
this._renderersProcessedPromise = new Promise(resolve => this._renderersProcessedResolve = resolve);
|
210
|
+
this._renderContainerRef = createRef();
|
211
211
|
|
212
212
|
const contextKeysPromise = getRenderers().then(renderers => renderers.reduce((keys, currentRenderer) => {
|
213
213
|
if (currentRenderer.contextKeys) currentRenderer.contextKeys.forEach(key => keys.push(key));
|
@@ -216,10 +216,7 @@ class HtmlBlock extends LitElement {
|
|
216
216
|
|
217
217
|
const contextValsPromise = contextKeysPromise.then(contextKeys => {
|
218
218
|
return Promise.allSettled(contextKeys.map(key => {
|
219
|
-
return tryGet(key, undefined, ctx =>
|
220
|
-
this._context.set(key, ctx);
|
221
|
-
this.updated(new Map([['_context']]));
|
222
|
-
});
|
219
|
+
return tryGet(key, undefined, ctx => this._context.set(key, ctx));
|
223
220
|
}));
|
224
221
|
});
|
225
222
|
|
@@ -238,24 +235,18 @@ class HtmlBlock extends LitElement {
|
|
238
235
|
};
|
239
236
|
|
240
237
|
return html`
|
241
|
-
<div class="${classMap(renderContainerClasses)}">
|
242
|
-
${!this.noDeferredRendering ? until(this._processEmbeds(), nothing) : nothing}
|
243
|
-
</div>
|
238
|
+
<div class="${classMap(renderContainerClasses)}" ${ref(this._renderContainerRef)}></div>
|
244
239
|
${this.noDeferredRendering ? html`<slot @slotchange="${this._handleSlotChange}"></slot>` : ''}
|
245
240
|
`;
|
246
241
|
}
|
247
242
|
|
248
243
|
async updated(changedProperties) {
|
249
244
|
super.updated(changedProperties);
|
250
|
-
if (
|
245
|
+
if (this.html !== undefined && this.html !== null && !this.noDeferredRendering) {
|
251
246
|
await this._updateRenderContainer();
|
252
247
|
}
|
253
248
|
}
|
254
249
|
|
255
|
-
async getLoadingComplete() {
|
256
|
-
return this._renderersProcessedPromise;
|
257
|
-
}
|
258
|
-
|
259
250
|
async _handleSlotChange(e) {
|
260
251
|
if (!e.target || !this.shadowRoot || !this.noDeferredRendering) return;
|
261
252
|
await this._renderInline(e.target);
|
@@ -264,7 +255,6 @@ class HtmlBlock extends LitElement {
|
|
264
255
|
async _processEmbeds() {
|
265
256
|
const htmlFragment = document.createRange().createContextualFragment(this.html);
|
266
257
|
await renderEmbeds(htmlFragment);
|
267
|
-
this.updated(new Map([['embeds']]));
|
268
258
|
return htmlFragment;
|
269
259
|
}
|
270
260
|
|
@@ -289,7 +279,7 @@ class HtmlBlock extends LitElement {
|
|
289
279
|
loadingCompletePromises.push(renderer.getLoadingComplete());
|
290
280
|
}
|
291
281
|
}
|
292
|
-
Promise.all(loadingCompletePromises).then(
|
282
|
+
Promise.all(loadingCompletePromises).then(this.resolveLoadingComplete);
|
293
283
|
}
|
294
284
|
|
295
285
|
async _renderInline(slot) {
|
@@ -300,15 +290,17 @@ class HtmlBlock extends LitElement {
|
|
300
290
|
.find(node => (node.nodeType === Node.ELEMENT_NODE && node.tagName === 'DIV'));
|
301
291
|
|
302
292
|
if (!noDeferredRenderingContainer) {
|
303
|
-
this.
|
293
|
+
this.resolveLoadingComplete();
|
304
294
|
return;
|
305
295
|
}
|
306
296
|
await this._processRenderers(noDeferredRenderingContainer);
|
307
297
|
}
|
308
298
|
|
309
299
|
async _updateRenderContainer() {
|
310
|
-
|
311
|
-
|
300
|
+
if (!this._renderContainerRef.value) return;
|
301
|
+
this._renderContainerRef.value.innerHTML = '';
|
302
|
+
this._renderContainerRef.value.append(await this._processEmbeds());
|
303
|
+
await this._processRenderers(this._renderContainerRef.value);
|
312
304
|
}
|
313
305
|
|
314
306
|
_validateHtml() {
|
package/custom-elements.json
CHANGED
@@ -4729,6 +4729,14 @@
|
|
4729
4729
|
"description": "Whether to disable deferred rendering of the user-authored HTML. Do *not* set this\nunless your HTML relies on script executions that may break upon stamping.",
|
4730
4730
|
"type": "Boolean",
|
4731
4731
|
"default": "false"
|
4732
|
+
},
|
4733
|
+
{
|
4734
|
+
"name": "loadingComplete",
|
4735
|
+
"type": "Promise<any>"
|
4736
|
+
},
|
4737
|
+
{
|
4738
|
+
"name": "resolveLoadingComplete",
|
4739
|
+
"type": "() => void"
|
4732
4740
|
}
|
4733
4741
|
]
|
4734
4742
|
},
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@brightspace-ui/core",
|
3
|
-
"version": "3.38.
|
3
|
+
"version": "3.38.3",
|
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",
|