@brightspace-ui/core 3.309.0 → 3.310.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,5 +1,5 @@
1
- import 'prismjs/prism.js';
2
1
  import { html, LitElement } from 'lit';
2
+ import { formatCodeElement } from '../../helpers/prism.js';
3
3
  import { styles } from './code-view-styles.js';
4
4
  import { themeStyles } from './code-dark-plus-styles.js';
5
5
  import { unsafeHTML } from 'lit/directives/unsafe-html.js';
@@ -17,17 +17,10 @@ class CodeView extends LitElement {
17
17
  constructor() {
18
18
  super();
19
19
  this.language = 'html';
20
- this._dependenciesPromise = Promise.resolve();
21
20
  }
22
21
 
23
22
  attributeChangedCallback(name, oldval, newval) {
24
23
  if (name !== 'language' || oldval === newval) return;
25
- const language = this._getLanguage(newval);
26
- if (Prism.languages[language]) {
27
- this._dependenciesPromise = Promise.resolve();
28
- } else {
29
- this._dependenciesPromise = import(`../../node_modules/prismjs/components/prism-${language}.min.js`);
30
- }
31
24
  if (this.shadowRoot) this._updateCode(this.shadowRoot.querySelector('slot'));
32
25
  super.attributeChangedCallback(name, oldval, newval);
33
26
  }
@@ -78,17 +71,6 @@ class CodeView extends LitElement {
78
71
  }).join('\n');
79
72
  }
80
73
 
81
- _getLanguage(language) {
82
- const aliases = { shell: 'bash' };
83
- return aliases[language] ? aliases[language] : language;
84
- }
85
-
86
- _getPrismGrammar(language) {
87
- language = this._getLanguage(language);
88
- if (Prism.languages[language]) return Prism.languages[language];
89
- else return Prism.languages.html;
90
- }
91
-
92
74
  _handleSlotChange(e) {
93
75
  this._updateCode(e.target);
94
76
  }
@@ -107,8 +89,11 @@ class CodeView extends LitElement {
107
89
  let code = this._formatCode(nodes.reduce((code, node) => code + node.textContent, ''));
108
90
 
109
91
  try {
110
- await this._dependenciesPromise;
111
- code = Prism.highlight(code, this._getPrismGrammar(this.language), this.language);
92
+ const codeElement = document.createElement('code');
93
+ codeElement.className = `language-${this.language}`;
94
+ codeElement.textContent = code;
95
+ await formatCodeElement(codeElement, { allowAllLanguages: true });
96
+ code = codeElement.innerHTML;
112
97
  } catch (ex) {
113
98
  // eslint-disable-next-line no-console
114
99
  console.log(ex);
@@ -6,8 +6,8 @@ import { css, html, LitElement } from 'lit';
6
6
  import { classMap } from 'lit/directives/class-map.js';
7
7
  import { DialogMixin } from './dialog-mixin.js';
8
8
  import { dialogStyles } from './dialog-styles.js';
9
+ import { getFlag } from '../../helpers/flags.js';
9
10
  import { getUniqueId } from '../../helpers/uniqueId.js';
10
- import { ifDefined } from 'lit/directives/if-defined.js';
11
11
  import { LocalizeCoreElement } from '../../helpers/localize-core-element.js';
12
12
  import { PropertyRequiredMixin } from '../../mixins/property-required/property-required-mixin.js';
13
13
  import { styleMap } from 'lit/directives/style-map.js';
@@ -49,6 +49,11 @@ class DialogFullscreen extends PropertyRequiredMixin(LocalizeCoreElement(AsyncCo
49
49
 
50
50
  static styles = [_generateResetStyles(':host'), dialogStyles, heading2Styles, heading3Styles, css`
51
51
 
52
+ .d2l-dialog-header > div {
53
+ display: flex;
54
+ flex-direction: row-reverse;
55
+ }
56
+
52
57
  .d2l-dialog-footer.d2l-footer-no-content {
53
58
  display: none;
54
59
  }
@@ -189,7 +194,7 @@ class DialogFullscreen extends PropertyRequiredMixin(LocalizeCoreElement(AsyncCo
189
194
  super();
190
195
  this.async = false;
191
196
  this.noPadding = false;
192
- this.preferNative = false;
197
+ this.preferNative = getFlag('GAUD-10336-prefer-native-fullscreen-dialogs', true);
193
198
  this._autoSize = false;
194
199
  this._hasFooterContent = false;
195
200
  this._icon = 'tier1:close-large-thick';
@@ -251,17 +256,15 @@ class DialogFullscreen extends PropertyRequiredMixin(LocalizeCoreElement(AsyncCo
251
256
  <div style=${styleMap(slotStyles)}><slot @slotchange="${this._handleSlotChange}"></slot></div>
252
257
  `;
253
258
 
254
- const contentTabIndex = !this.focusableContentElemPresent ? '0' : undefined;
255
-
256
259
  const inner = html`
257
260
  <div class="d2l-dialog-inner" style=${styleMap(heightOverride)}>
258
261
  <div class="d2l-dialog-header">
259
262
  <div>
260
- <h2 id="${this._titleId}" class="${this._headerStyle}">${this.titleText}</h2>
261
263
  <d2l-button-icon icon="${this._icon}" text="${this.localize('components.dialog.close')}" @click="${this._abort}"></d2l-button-icon>
264
+ ${this._renderHeading(this.titleText, { id: this._titleId, class: this._headerStyle })}
262
265
  </div>
263
266
  </div>
264
- <div class="d2l-dialog-content" @pending-state="${this._handleAsyncItemState}" tabindex="${ifDefined(contentTabIndex)}">${content}</div>
267
+ ${this._renderContent(content, { handleAsyncItemState: this._handleAsyncItemState, hasTitleText: !!this.titleText })}
265
268
  <div class="${classMap(footerClasses)}">
266
269
  <slot name="footer" @slotchange="${this._handleFooterSlotChange}"></slot>
267
270
  </div>
@@ -296,6 +299,11 @@ class DialogFullscreen extends PropertyRequiredMixin(LocalizeCoreElement(AsyncCo
296
299
  this._close('abort');
297
300
  }
298
301
 
302
+ _focusInitial() {
303
+ if (!this.shadowRoot || this._useNative) return;
304
+ else super._focusInitial();
305
+ }
306
+
299
307
  _handleFooterSlotChange(e) {
300
308
  const footerContent = e.target.assignedNodes({ flatten: true });
301
309
  this._hasFooterContent = (footerContent && footerContent.length > 0);
@@ -582,6 +582,32 @@ export const DialogMixin = superclass => class extends superclass {
582
582
 
583
583
  }
584
584
 
585
+ _renderContent(content, options) {
586
+ let tabIndex = undefined;
587
+ let autoFocus = false;
588
+ if (this._useNative) {
589
+ if (!options.hasTitleText) {
590
+ tabIndex = '-1';
591
+ autoFocus = true;
592
+ }
593
+ } else {
594
+ tabIndex = !this.focusableContentElemPresent ? '0' : undefined;
595
+ }
596
+ return html`<div ?autofocus="${autoFocus}" class="d2l-dialog-content" @pending-state="${ifDefined(options.handleAsyncItemState)}" tabindex="${ifDefined(tabIndex)}">${content}</div>`;
597
+ }
598
+
599
+ _renderHeading(text, options) {
600
+ let tabIndex = undefined;
601
+ let autoFocus = false;
602
+ if (this._useNative) {
603
+ if (text) {
604
+ tabIndex = '-1';
605
+ autoFocus = true;
606
+ }
607
+ }
608
+ return html`<h2 ?autofocus="${autoFocus}" class="${ifDefined(options.class)}" id="${ifDefined(options.id)}" tabindex="${ifDefined(tabIndex)}">${text}</h2>`;
609
+ }
610
+
585
611
  _tryApplyFocus(node) {
586
612
  const focusable = getFirstFocusableRelative(node);
587
613
  if (focusable) focusable.focus();
@@ -2976,7 +2976,6 @@
2976
2976
  },
2977
2977
  {
2978
2978
  "name": "preferNative",
2979
- "type": "boolean",
2980
2979
  "default": "false"
2981
2980
  }
2982
2981
  ],
package/helpers/prism.js CHANGED
@@ -330,13 +330,17 @@ export const codeStyles = css`
330
330
  }
331
331
  `;
332
332
 
333
- const getLanguageInfo = elem => {
333
+ const languageAliases = {
334
+ shell: 'bash'
335
+ };
336
+
337
+ const getLanguageInfo = (elem, allowAllLanguages) => {
334
338
  const classes = elem.classList;
335
339
  for (let i = 0; i < classes.length; i++) {
336
340
  if (classes[i].startsWith('language-')) {
337
341
  const key = classes[i].substring(9);
338
342
  const desc = codeLanguages.get(key);
339
- if (desc) return { key: key, desc: desc };
343
+ if (desc || allowAllLanguages) return { key: languageAliases[key] || key, desc: desc };
340
344
  }
341
345
  }
342
346
  return { key: 'plain', desc: codeLanguages.get('plain') };
@@ -351,6 +355,7 @@ const languageDependencies = {
351
355
  const languagesLoaded = {
352
356
  clike: Promise.resolve(),
353
357
  css: Promise.resolve(),
358
+ html: Promise.resolve(),
354
359
  javascript: Promise.resolve(),
355
360
  markup: Promise.resolve(),
356
361
  plain: Promise.resolve()
@@ -442,12 +447,13 @@ const getCodeElement = elem => {
442
447
  return elem.querySelector('code');
443
448
  };
444
449
 
445
- export async function formatCodeElement(elem) {
450
+ // allowAllLanguages is intended only for development consumers.
451
+ export async function formatCodeElement(elem, { allowAllLanguages = false } = {}) {
446
452
  const code = getCodeElement(elem);
447
453
 
448
454
  if (code.className.indexOf('language-') === -1) return;
449
455
 
450
- const languageInfo = getLanguageInfo(code);
456
+ const languageInfo = getLanguageInfo(code, allowAllLanguages);
451
457
  const lineNumbers = elem.classList.contains('line-numbers') || code.classList.contains('line-numbers');
452
458
 
453
459
  await loadPrism(); // must be loaded before loading plugins or languages
@@ -457,7 +463,7 @@ export async function formatCodeElement(elem) {
457
463
  lineNumbers ? loadPlugin('line-numbers') : null
458
464
  ]);
459
465
 
460
- if (!elem.dataset.language && languageInfo.key !== 'plain') elem.dataset.language = languageInfo.desc;
466
+ if (!elem.dataset.language && languageInfo.desc && languageInfo.key !== 'plain') elem.dataset.language = languageInfo.desc;
461
467
  Prism.highlightElement(code);
462
468
  }
463
469
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brightspace-ui/core",
3
- "version": "3.309.0",
3
+ "version": "3.310.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",