@ni/nimble-components 24.1.9 → 24.1.11

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.
@@ -1715,8 +1715,20 @@
1715
1715
  return prev.concat(curr);
1716
1716
  }, null);
1717
1717
  }
1718
+ /**
1719
+ * A Symbol that can be added to a CSSStyleSheet to cause it to be prepended (rather than appended) to adoptedStyleSheets.
1720
+ * @public
1721
+ */
1722
+ const prependToAdoptedStyleSheetsSymbol = Symbol("prependToAdoptedStyleSheets");
1723
+ function separateSheetsToPrepend(sheets) {
1724
+ const prepend = [];
1725
+ const append = [];
1726
+ sheets.forEach(x => (x[prependToAdoptedStyleSheetsSymbol] ? prepend : append).push(x));
1727
+ return { prepend, append };
1728
+ }
1718
1729
  let addAdoptedStyleSheets = (target, sheets) => {
1719
- target.adoptedStyleSheets = [...target.adoptedStyleSheets, ...sheets];
1730
+ const { prepend, append } = separateSheetsToPrepend(sheets);
1731
+ target.adoptedStyleSheets = [...prepend, ...target.adoptedStyleSheets, ...append];
1720
1732
  };
1721
1733
  let removeAdoptedStyleSheets = (target, sheets) => {
1722
1734
  target.adoptedStyleSheets = target.adoptedStyleSheets.filter((x) => sheets.indexOf(x) === -1);
@@ -1731,7 +1743,9 @@
1731
1743
  document.adoptedStyleSheets.push();
1732
1744
  document.adoptedStyleSheets.splice();
1733
1745
  addAdoptedStyleSheets = (target, sheets) => {
1734
- target.adoptedStyleSheets.push(...sheets);
1746
+ const { prepend, append } = separateSheetsToPrepend(sheets);
1747
+ target.adoptedStyleSheets.splice(0, 0, ...prepend);
1748
+ target.adoptedStyleSheets.push(...append);
1735
1749
  };
1736
1750
  removeAdoptedStyleSheets = (target, sheets) => {
1737
1751
  for (const sheet of sheets) {
@@ -9040,6 +9054,7 @@
9040
9054
  constructor(source) {
9041
9055
  super();
9042
9056
  const sheet = new CSSStyleSheet();
9057
+ sheet[prependToAdoptedStyleSheetsSymbol] = true;
9043
9058
  this.target = sheet.cssRules[sheet.insertRule(":host{}")].style;
9044
9059
  source.$fastController.addStyles(ElementStyles.create([sheet]));
9045
9060
  }
@@ -9476,23 +9491,7 @@
9476
9491
  if (token) {
9477
9492
  // Notify any token subscribers
9478
9493
  token.notify(this.target);
9479
- if (DesignTokenImpl.isCSSDesignToken(token)) {
9480
- const parent = this.parent;
9481
- const reflecting = this.isReflecting(token);
9482
- if (parent) {
9483
- const parentValue = parent.get(token);
9484
- const sourceValue = source.get(token);
9485
- if (parentValue !== sourceValue && !reflecting) {
9486
- this.reflectToCSS(token);
9487
- }
9488
- else if (parentValue === sourceValue && reflecting) {
9489
- this.stopReflectToCSS(token);
9490
- }
9491
- }
9492
- else if (!reflecting) {
9493
- this.reflectToCSS(token);
9494
- }
9495
- }
9494
+ this.updateCSSTokenReflection(source, token);
9496
9495
  }
9497
9496
  },
9498
9497
  };
@@ -9566,6 +9565,25 @@
9566
9565
  get parent() {
9567
9566
  return childToParent.get(this) || null;
9568
9567
  }
9568
+ updateCSSTokenReflection(source, token) {
9569
+ if (DesignTokenImpl.isCSSDesignToken(token)) {
9570
+ const parent = this.parent;
9571
+ const reflecting = this.isReflecting(token);
9572
+ if (parent) {
9573
+ const parentValue = parent.get(token);
9574
+ const sourceValue = source.get(token);
9575
+ if (parentValue !== sourceValue && !reflecting) {
9576
+ this.reflectToCSS(token);
9577
+ }
9578
+ else if (parentValue === sourceValue && reflecting) {
9579
+ this.stopReflectToCSS(token);
9580
+ }
9581
+ }
9582
+ else if (!reflecting) {
9583
+ this.reflectToCSS(token);
9584
+ }
9585
+ }
9586
+ }
9569
9587
  /**
9570
9588
  * Checks if a token has been assigned an explicit value the node.
9571
9589
  * @param token - the token to check.
@@ -9731,6 +9749,7 @@
9731
9749
  return;
9732
9750
  }
9733
9751
  this.hydrate(token, this.getRaw(token));
9752
+ this.updateCSSTokenReflection(this.store, token);
9734
9753
  }
9735
9754
  /**
9736
9755
  * Hydrates a token with a DesignTokenValue, making retrieval available.
@@ -11220,7 +11239,7 @@
11220
11239
  item.setAttribute("tabindex", index === 0 ? "0" : "-1");
11221
11240
  item.addEventListener("expanded-change", this.handleExpandedChanged);
11222
11241
  item.addEventListener("focus", this.handleItemFocus);
11223
- if (item instanceof MenuItem$1) {
11242
+ if (item instanceof MenuItem$1 || "startColumnCount" in item) {
11224
11243
  item.startColumnCount = indent;
11225
11244
  }
11226
11245
  });
@@ -13869,6 +13888,15 @@
13869
13888
  </template>
13870
13889
  `;
13871
13890
 
13891
+ // returns the active element in the shadow context of the element in question.
13892
+ function getRootActiveElement(element) {
13893
+ const rootNode = element.getRootNode();
13894
+ if (rootNode instanceof ShadowRoot) {
13895
+ return rootNode.activeElement;
13896
+ }
13897
+ return document.activeElement;
13898
+ }
13899
+
13872
13900
  /**
13873
13901
  * A map for directionality derived from keyboard input strings,
13874
13902
  * visual orientation, and text direction.
@@ -14053,10 +14081,14 @@
14053
14081
  * @internal
14054
14082
  */
14055
14083
  setFocusedElement(activeIndex = this.activeIndex) {
14056
- var _a;
14057
14084
  this.activeIndex = activeIndex;
14058
14085
  this.setFocusableElements();
14059
- (_a = this.focusableElements[this.activeIndex]) === null || _a === void 0 ? void 0 : _a.focus();
14086
+ if (this.focusableElements[this.activeIndex] &&
14087
+ // Don't focus the toolbar element if some event handlers moved
14088
+ // the focus on another element in the page.
14089
+ this.contains(getRootActiveElement(this))) {
14090
+ this.focusableElements[this.activeIndex].focus();
14091
+ }
14060
14092
  }
14061
14093
  /**
14062
14094
  * Reduce a collection to only its focusable elements.
@@ -16301,7 +16333,7 @@
16301
16333
 
16302
16334
  /**
16303
16335
  * Do not edit directly
16304
- * Generated on Mon, 08 Apr 2024 20:24:00 GMT
16336
+ * Generated on Wed, 10 Apr 2024 17:29:50 GMT
16305
16337
  */
16306
16338
 
16307
16339
  const Information100DarkUi = "#a46eff";
@@ -16956,7 +16988,7 @@
16956
16988
  const [linkFont, linkFontColor, linkDisabledFontColor, linkFontFamily, linkFontWeight, linkFontSize, linkFontLineHeight, linkFallbackFontFamily] = createFontTokens(tokenNames.linkFont, (element) => getDefaultFontColorForTheme(element), (element) => hexToRgbaCssColor(getDefaultFontColorForTheme(element), 0.3), LinkLightUiFamily, LinkLightUiWeight, LinkLightUiSize, LinkLineHeight, LinkFallbackFontFamily);
16957
16989
  const [linkActiveFont, linkActiveFontColor, linkActiveDisabledFontColor, linkActiveFontFamily, linkActiveFontWeight, linkActiveFontSize, linkActiveFontLineHeight, linkActiveFallbackFontFamily] = createFontTokens(tokenNames.linkActiveFont, (element) => getColorForTheme(element, DigitalGreenLight, DigitalGreenLight, hexToRgbaCssColor(White, 0.6)), (element) => hexToRgbaCssColor(getDefaultFontColorForTheme(element), 0.3), LinkLightUiFamily, LinkLightUiWeight, LinkLightUiSize, LinkLineHeight, LinkFallbackFontFamily);
16958
16990
  const [linkProminentFont, linkProminentFontColor, linkProminentDisabledFontColor, linkProminentFontFamily, linkProminentFontWeight, linkProminentFontSize, linkProminentFontLineHeight, linkProminentFallbackFontFamily] = createFontTokens(tokenNames.linkProminentFont, (element) => getColorForTheme(element, DigitalGreenDark105, PowerGreen, PowerGreen), (element) => hexToRgbaCssColor(getDefaultFontColorForTheme(element), 0.3), LinkLightUiFamily, LinkLightUiWeight, LinkLightUiSize, LinkLineHeight, LinkFallbackFontFamily);
16959
- const [linkActiveProminentFont, linkActiveProminentFontColor, linkActiveProminentDisabledFontColor, linkActiveProminentFontFamily, linkActiveProminentFontWeight, linkActiveProminentFontSize, linkActiveProminentFontLineHeight, linkActiveProminentFallbackFontFamily] = createFontTokens(tokenNames.linkActiveProminentFont, (element) => getColorForTheme(element, DigitalGreenLight, DigitalGreenLight, PowerGreen), (element) => hexToRgbaCssColor(getDefaultFontColorForTheme(element), 0.3), LinkLightUiFamily, LinkLightUiWeight, LinkLightUiSize, LinkLineHeight, LinkFallbackFontFamily);
16991
+ const [linkActiveProminentFont, linkActiveProminentFontColor, linkActiveProminentDisabledFontColor, linkActiveProminentFontFamily, linkActiveProminentFontWeight, linkActiveProminentFontSize, linkActiveProminentFontLineHeight, linkActiveProminentFallbackFontFamily] = createFontTokens(tokenNames.linkActiveProminentFont, (element) => getColorForTheme(element, DigitalGreenLight, DigitalGreenLight, hexToRgbaCssColor(White, 0.6)), (element) => hexToRgbaCssColor(getDefaultFontColorForTheme(element), 0.3), LinkLightUiFamily, LinkLightUiWeight, LinkLightUiSize, LinkLineHeight, LinkFallbackFontFamily);
16960
16992
  const [placeholderFont, placeholderFontColor, placeholderDisabledFontColor, placeholderFontFamily, placeholderFontWeight, placeholderFontSize, placeholderFontLineHeight, placeholderFallbackFontFamily] = createFontTokens(tokenNames.placeholderFont, (element) => hexToRgbaCssColor(getDefaultFontColorForTheme(element), 0.6), (element) => hexToRgbaCssColor(getDefaultFontColorForTheme(element), 0.3), PlaceholderFamily, PlaceholderWeight, PlaceholderSize, PlaceholderLineHeight, PlaceholderFallbackFontFamily);
16961
16993
  const [bodyFont, bodyFontColor, bodyDisabledFontColor, bodyFontFamily, bodyFontWeight, bodyFontSize, bodyFontLineHeight, bodyFallbackFontFamily] = createFontTokens(tokenNames.bodyFont, (element) => getDefaultFontColorForTheme(element), (element) => hexToRgbaCssColor(getDefaultFontColorForTheme(element), 0.3), BodyFamily, BodyWeight, BodySize, BodyLineHeight, BodyFallbackFontFamily);
16962
16994
  const [bodyEmphasizedFont, bodyEmphasizedFontColor, bodyEmphasizedDisabledFontColor, bodyEmphasizedFontFamily, bodyEmphasizedFontWeight, bodyEmphasizedFontSize, bodyEmphasizedFontLineHeight, bodyEmphasizedFallbackFontFamily] = createFontTokens(tokenNames.bodyEmphasizedFont, (element) => getDefaultFontColorForTheme(element), (element) => hexToRgbaCssColor(getDefaultFontColorForTheme(element), 0.3), BodyEmphasizedFamily, BodyEmphasizedWeight, BodyEmphasizedSize, BodyEmphasizedLineHeight, BodyEmphasizedFallbackFontFamily);
@@ -17066,92 +17098,80 @@
17066
17098
  }
17067
17099
 
17068
17100
  const styles$W = css `
17069
- ${display('inline')}
17101
+ @layer base, hover, focusVisible, active, disabled;
17070
17102
 
17071
- :host {
17072
- box-sizing: border-box;
17073
- font: ${linkFont};
17074
- }
17075
-
17076
- .top-container {
17077
- display: contents;
17078
- }
17079
-
17080
- [part='start'] {
17081
- display: none;
17082
- }
17083
-
17084
- .control {
17085
- color: ${linkFontColor};
17086
- text-decoration: underline;
17087
- }
17088
-
17089
- .control${focusVisible} {
17090
- display: inline;
17091
- outline: none;
17092
- box-shadow: inset 0px -1px ${linkFontColor};
17093
- }
17094
-
17095
- .control:active {
17096
- color: ${linkActiveFontColor};
17097
- text-decoration: underline;
17098
- }
17103
+ @layer base {
17104
+ ${display('inline')}
17099
17105
 
17100
- .control${focusVisible}:active {
17101
- box-shadow: inset 0px -1px ${linkActiveFontColor};
17102
- }
17106
+ :host {
17107
+ box-sizing: border-box;
17108
+ font: ${linkFont};
17109
+ }
17103
17110
 
17104
- .control:not(:any-link) {
17105
- color: ${linkDisabledFontColor};
17106
- text-decoration: none;
17107
- }
17111
+ .top-container {
17112
+ display: contents;
17113
+ }
17108
17114
 
17109
- .control:not(:any-link):active {
17110
- color: ${linkActiveDisabledFontColor};
17111
- }
17115
+ .control {
17116
+ color: ${linkFontColor};
17117
+ text-decoration: underline;
17118
+ }
17112
17119
 
17113
- :host([underline-hidden]) .control {
17114
- text-decoration: none;
17115
- }
17120
+ :host([underline-hidden]) .control {
17121
+ text-decoration: none;
17122
+ }
17116
17123
 
17117
- :host([underline-hidden]) .control:hover {
17118
- text-decoration: underline;
17119
- }
17124
+ :host([appearance='prominent']) .control {
17125
+ color: ${linkProminentFontColor};
17126
+ }
17120
17127
 
17121
- :host([underline-hidden]) .control${focusVisible} {
17122
- text-decoration: underline;
17123
- }
17128
+ [part='start'] {
17129
+ display: none;
17130
+ }
17124
17131
 
17125
- :host([underline-hidden]) .control:not(:any-link) {
17126
- text-decoration: none;
17127
- }
17132
+ .content {
17133
+ pointer-events: none;
17134
+ }
17128
17135
 
17129
- :host([appearance='prominent']) .control {
17130
- color: ${linkProminentFontColor};
17136
+ [part='end'] {
17137
+ display: none;
17138
+ }
17131
17139
  }
17132
17140
 
17133
- :host([appearance='prominent']) .control:active {
17134
- color: ${linkActiveProminentFontColor};
17141
+ @layer hover {
17142
+ .control:any-link:hover {
17143
+ text-decoration: underline;
17144
+ }
17135
17145
  }
17136
17146
 
17137
- :host([appearance='prominent']) .control${focusVisible} {
17138
- box-shadow: inset 0px -1px ${linkProminentFontColor};
17147
+ @layer focusVisible {
17148
+ .control${focusVisible} {
17149
+ outline: none;
17150
+ box-shadow: inset 0px -1px;
17151
+ text-decoration: underline;
17152
+ }
17139
17153
  }
17140
17154
 
17141
- :host([appearance='prominent']) .control${focusVisible}:active {
17142
- box-shadow: inset 0px -1px ${linkActiveProminentFontColor};
17143
- }
17155
+ @layer active {
17156
+ .control:active {
17157
+ color: ${linkActiveFontColor};
17158
+ text-decoration: underline;
17159
+ box-shadow: none;
17160
+ }
17144
17161
 
17145
- :host([appearance='prominent']) .control:not(:any-link) {
17146
- color: ${linkProminentDisabledFontColor};
17147
- }
17162
+ :host([appearance='prominent']) .control:active {
17163
+ color: ${linkActiveProminentFontColor};
17164
+ }
17148
17165
 
17149
- .content {
17150
- pointer-events: none;
17166
+ :host([underline-hidden]) .control:active {
17167
+ text-decoration: none;
17168
+ }
17151
17169
  }
17152
17170
 
17153
- [part='end'] {
17154
- display: none;
17171
+ @layer disabled {
17172
+ .control:not(:any-link) {
17173
+ color: ${linkDisabledFontColor};
17174
+ }
17155
17175
  }
17156
17176
  `;
17157
17177
 
@@ -17941,20 +17961,6 @@
17941
17961
  DesignSystem.getOrCreate()
17942
17962
  .withPrefix('nimble')
17943
17963
  .register(nimbleAnchorMenuItem());
17944
- // This is a workaround for the fact that FAST's menu uses `instanceof MenuItem`
17945
- // in their logic for indenting menu items. Since our AnchorMenuItem derives from
17946
- // AnchorBase and not FAST's MenuItem, we need to change their MenuItem's definition
17947
- // of `hasInstance` so that it includes our AnchorMenuItem, too.
17948
- //
17949
- // If/when we change FAST to test for the presence of `startColumnCount` instead
17950
- // of using `instanceof MenuItem`, we can remove this workaround. Here is the
17951
- // PR into FAST: https://github.com/microsoft/fast/pull/6667
17952
- const originalInstanceOf = MenuItem$1[Symbol.hasInstance].bind(MenuItem$1);
17953
- Object.defineProperty(MenuItem$1, Symbol.hasInstance, {
17954
- value(instance) {
17955
- return (originalInstanceOf(instance) || instance instanceof AnchorMenuItem);
17956
- }
17957
- });
17958
17964
 
17959
17965
  const styles$S = css `
17960
17966
  ${display('inline-flex')}
@@ -20070,7 +20076,7 @@
20070
20076
 
20071
20077
  .control:active {
20072
20078
  color: var(--ni-private-breadcrumb-link-active-font-color);
20073
- text-decoration: underline;
20079
+ text-decoration: none;
20074
20080
  }
20075
20081
 
20076
20082
  [part='start'] {
@@ -53283,12 +53289,17 @@ img.ProseMirror-separator {
53283
53289
  * scheme and no matching mention pattern will be rendered as plain text (anchor with no href).
53284
53290
  * With this, the user can click the links only when the scheme is HTTP/HTTPS
53285
53291
  */
53286
- href: /^https?:\/\//i.test(href) ? href : null,
53292
+ href: RichTextMarkdownParser.startsWithHttpOrHttps(href)
53293
+ ? href
53294
+ : null,
53287
53295
  rel: node.attrs.rel,
53288
53296
  // Adding `class` here is a workaround to render two mentions without a whitespace as display names
53289
53297
  // This attribute can be removed when the below issue is resolved
53290
53298
  // https://github.com/ni/nimble/issues/1707
53291
- class: href
53299
+ class: href,
53300
+ 'underline-hidden': RichTextMarkdownParser.startsWithHttpOrHttps(href)
53301
+ ? null
53302
+ : true
53292
53303
  }
53293
53304
  ];
53294
53305
  }
@@ -53306,6 +53317,9 @@ img.ProseMirror-separator {
53306
53317
  RichTextMarkdownParser.mentionConfigs = undefined;
53307
53318
  RichTextMarkdownParser.mentionedHrefs.clear();
53308
53319
  }
53320
+ static startsWithHttpOrHttps(href) {
53321
+ return /^https?:\/\//i.test(href);
53322
+ }
53309
53323
  }
53310
53324
  _a$1 = RichTextMarkdownParser;
53311
53325
  RichTextMarkdownParser.mentionedHrefs = new Set();
@@ -58320,10 +58334,13 @@ img.ProseMirror-separator {
58320
58334
 
58321
58335
  ${
58322
58336
  /**
58323
- * When an absolute link is not HTTPS/HTTP, the anchor tag renders without an `href`, appearing as plain text.
58324
- * However, the `nimble-anchor` displays differently in color when the `href` attribute is absent.
58325
- * To ensure a consistent appearance, the font color is forced to the default link color regardless of the `href`
58326
- * attribute's presence.
58337
+ * In the rich-text editor, an absolute link renders as a native anchor, not a `nimble-anchor`. When such a link
58338
+ * is not HTTPS/HTTP, the anchor renders without an `href`, appearing as plain text.
58339
+ * However, in the rich-text viewer, absolute links are rendered as `nimble-anchor`s, and they do not look like
58340
+ * plain text when the `href` attribute is absent. They have a "disabled" color and may have an underline.
58341
+ * To ensure a consistent appearance between the editor and viewer, we force the font color to the default link/
58342
+ * plain text color regardless of the `href` attribute's presence. To remove the underline, the markdown parser
58343
+ * emits an `underline-hidden` attribute when the `href` attribute is absent.
58327
58344
  *
58328
58345
  * See models/markdown-parser.ts where link elements are emitted for more info.
58329
58346
  */ ''}