vira 32.4.0 → 33.1.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.
Files changed (58) hide show
  1. package/dist/directives/index.d.ts +2 -0
  2. package/dist/directives/index.js +2 -0
  3. package/dist/directives/popover.directive.d.ts +29 -0
  4. package/dist/directives/popover.directive.js +45 -0
  5. package/dist/directives/tooltip.directive.d.ts +60 -0
  6. package/dist/directives/tooltip.directive.js +99 -0
  7. package/dist/elements/color/vira-color-picker.element.d.ts +1 -1
  8. package/dist/elements/color/vira-color-picker.element.js +17 -15
  9. package/dist/elements/index.d.ts +5 -5
  10. package/dist/elements/index.js +5 -5
  11. package/dist/elements/{pop-up → popover}/vira-menu-item.element.d.ts +4 -4
  12. package/dist/elements/{pop-up → popover}/vira-menu-item.element.js +12 -3
  13. package/dist/elements/popover/vira-menu-trigger.element.d.ts +56 -0
  14. package/dist/elements/{pop-up → popover}/vira-menu-trigger.element.js +19 -30
  15. package/dist/elements/popover/vira-menu.element.d.ts +35 -0
  16. package/dist/elements/popover/vira-menu.element.js +262 -0
  17. package/dist/elements/popover/vira-popover-trigger.element.d.ts +50 -0
  18. package/dist/elements/popover/vira-popover-trigger.element.js +307 -0
  19. package/dist/elements/popover/vira-tooltip.element.d.ts +10 -0
  20. package/dist/elements/popover/vira-tooltip.element.js +176 -0
  21. package/dist/elements/vira-drawer.element.js +1 -1
  22. package/dist/elements/vira-dropdown.element.d.ts +40 -13
  23. package/dist/elements/vira-dropdown.element.js +375 -69
  24. package/dist/elements/vira-form.element.js +10 -16
  25. package/dist/elements/vira-json-form.element.js +40 -36
  26. package/dist/elements/vira-modal.element.js +1 -1
  27. package/dist/elements/vira-tabs.element.d.ts +3 -9
  28. package/dist/elements/vira-tabs.element.js +5 -6
  29. package/dist/elements/vira-theme-switcher.element.js +3 -3
  30. package/dist/index.d.ts +1 -0
  31. package/dist/index.js +1 -0
  32. package/dist/util/anchored-popover.d.ts +40 -0
  33. package/dist/util/anchored-popover.js +70 -0
  34. package/dist/util/fuzzy-match.d.ts +16 -0
  35. package/dist/util/fuzzy-match.js +24 -0
  36. package/dist/util/index.d.ts +5 -3
  37. package/dist/util/index.js +5 -3
  38. package/dist/util/{pop-up-helpers.d.ts → menu-helpers.d.ts} +8 -19
  39. package/dist/util/{pop-up-helpers.js → menu-helpers.js} +12 -19
  40. package/dist/util/popover-manager.d.ts +123 -0
  41. package/dist/util/popover-manager.js +414 -0
  42. package/dist/util/vira-dropdown-option.d.ts +30 -0
  43. package/dist/util/vira-dropdown-option.js +8 -0
  44. package/dist/util/vira-form-fields.d.ts +2 -2
  45. package/dist/util/vira-theme-client.d.ts +1 -1
  46. package/dist/util/vira-theme-client.js +3 -3
  47. package/package.json +2 -1
  48. package/dist/elements/pop-up/vira-menu-trigger.element.d.ts +0 -45
  49. package/dist/elements/pop-up/vira-menu.element.d.ts +0 -36
  50. package/dist/elements/pop-up/vira-menu.element.js +0 -88
  51. package/dist/elements/pop-up/vira-pop-up-trigger.element.d.ts +0 -109
  52. package/dist/elements/pop-up/vira-pop-up-trigger.element.js +0 -408
  53. package/dist/elements/vira-select.element.d.ts +0 -44
  54. package/dist/elements/vira-select.element.js +0 -418
  55. package/dist/util/pop-up-manager.d.ts +0 -200
  56. package/dist/util/pop-up-manager.js +0 -258
  57. package/dist/util/vira-select-option.d.ts +0 -31
  58. package/dist/util/vira-select-option.js +0 -8
@@ -9,9 +9,9 @@ import { defineViraElement } from '../util/define-vira-element.js';
9
9
  import { allowsFreeformString, createDefaultForJsonType, createResolveContext, deleteValueAtPath, getAdditionalPropertiesSchema, getAllowedJsonTypes, getDefinedProperties, getItemSchema, getJsonType, getNewItemSchema, getPropertySchema, getRequiredProperties, getSchemaEnumValues, getSchemaTitle, getStringEnumValues, pathToKey, pickBranchForType, setValueAtPath, validateAgainstSchema, ViraJsonType, viraJsonTypeLabels, } from '../util/vira-json-schema.js';
10
10
  import { ViraButton } from './vira-button.element.js';
11
11
  import { ViraCheckbox } from './vira-checkbox.element.js';
12
+ import { ViraDropdown } from './vira-dropdown.element.js';
12
13
  import { ViraError } from './vira-error.element.js';
13
14
  import { ViraInput, ViraInputType } from './vira-input.element.js';
14
- import { ViraSelect } from './vira-select.element.js';
15
15
  import { ViraTextArea } from './vira-text-area.element.js';
16
16
  /**
17
17
  * Editing mode for a string field that offers both a fixed set of enum options and free-form text.
@@ -25,6 +25,9 @@ export var ViraJsonStringMode;
25
25
  /** Enter an arbitrary string via a text input. */
26
26
  ViraJsonStringMode["Custom"] = "custom";
27
27
  })(ViraJsonStringMode || (ViraJsonStringMode = {}));
28
+ function toSelectedValues(value) {
29
+ return value == undefined ? [] : [value];
30
+ }
28
31
  /**
29
32
  * An editor for arbitrary JSON values, optionally constrained by a standard JSON Schema
30
33
  * ({@link ViraJsonSchema}).
@@ -163,7 +166,7 @@ export const ViraJsonForm = defineViraElement()({
163
166
  min-width: 0;
164
167
  }
165
168
 
166
- .json-value-with-switcher > ${ViraSelect} {
169
+ .json-value-with-switcher > ${ViraDropdown} {
167
170
  flex-shrink: 0;
168
171
  width: 130px;
169
172
  }
@@ -177,7 +180,7 @@ export const ViraJsonForm = defineViraElement()({
177
180
  padding: 8px 0;
178
181
  }
179
182
 
180
- .json-add-row ${ViraInput}, .json-add-row ${ViraSelect} {
183
+ .json-add-row ${ViraInput}, .json-add-row ${ViraDropdown} {
181
184
  width: 160px;
182
185
  }
183
186
 
@@ -310,16 +313,17 @@ export const ViraJsonForm = defineViraElement()({
310
313
  check.isNumber(value) ||
311
314
  check.isBoolean(value);
312
315
  return html `
313
- <${ViraSelect.assign({
316
+ <${ViraDropdown.assign({
314
317
  options,
315
- value: isPrimitive ? jsonPrimitiveToString(value) : undefined,
316
- disabled: isDisabled,
318
+ selected: toSelectedValues(isPrimitive ? jsonPrimitiveToString(value) : undefined),
319
+ isDisabled,
317
320
  })}
318
- ${listen(ViraSelect.events.valueChange, (event) => {
319
- const selected = enumValues.find((entry) => jsonPrimitiveToString(entry) === event.detail);
320
- emitReplaceAt(path, selected ?? event.detail);
321
+ ${listen(ViraDropdown.events.selectedValuesChange, (event) => {
322
+ const selectedValue = assertWrap.isDefined(event.detail[0]);
323
+ const selected = enumValues.find((entry) => jsonPrimitiveToString(entry) === selectedValue);
324
+ emitReplaceAt(path, selected ?? selectedValue);
321
325
  })}
322
- ></${ViraSelect}>
326
+ ></${ViraDropdown}>
323
327
  `;
324
328
  }
325
329
  else if (type === ViraJsonType.Boolean) {
@@ -463,14 +467,14 @@ export const ViraJsonForm = defineViraElement()({
463
467
  };
464
468
  });
465
469
  return html `
466
- <${ViraSelect.assign({
470
+ <${ViraDropdown.assign({
467
471
  options,
468
- value: selectedType,
472
+ selected: toSelectedValues(selectedType),
469
473
  })}
470
- ${listen(ViraSelect.events.valueChange, (event) => {
471
- setPendingType(pathKey, event.detail);
474
+ ${listen(ViraDropdown.events.selectedValuesChange, (event) => {
475
+ setPendingType(pathKey, assertWrap.isDefined(event.detail[0]));
472
476
  })}
473
- ></${ViraSelect}>
477
+ ></${ViraDropdown}>
474
478
  ${renderPlusButton({
475
479
  isAddDisabled,
476
480
  tooltip: isAddDisabled
@@ -527,14 +531,14 @@ export const ViraJsonForm = defineViraElement()({
527
531
  };
528
532
  });
529
533
  return html `
530
- <${ViraSelect.assign({
534
+ <${ViraDropdown.assign({
531
535
  options,
532
- value: selectedType,
536
+ selected: toSelectedValues(selectedType),
533
537
  })}
534
- ${listen(ViraSelect.events.valueChange, (event) => {
535
- setPendingType(pathKey, event.detail);
538
+ ${listen(ViraDropdown.events.selectedValuesChange, (event) => {
539
+ setPendingType(pathKey, assertWrap.isDefined(event.detail[0]));
536
540
  })}
537
- ></${ViraSelect}>
541
+ ></${ViraDropdown}>
538
542
  ${renderPlusButton({
539
543
  isAddDisabled: false,
540
544
  tooltip: `Add ${viraJsonTypeLabels[selectedType]}`,
@@ -798,20 +802,20 @@ export const ViraJsonForm = defineViraElement()({
798
802
  });
799
803
  const editor = mode === ViraJsonStringMode.Options
800
804
  ? html `
801
- <${ViraSelect.assign({
805
+ <${ViraDropdown.assign({
802
806
  options: enumValues.map((entry) => {
803
807
  return {
804
808
  value: entry,
805
809
  label: entry,
806
810
  };
807
811
  }),
808
- value: enumValues.includes(value) ? value : undefined,
809
- disabled: isDisabled,
812
+ selected: toSelectedValues(enumValues.includes(value) ? value : undefined),
813
+ isDisabled,
810
814
  })}
811
- ${listen(ViraSelect.events.valueChange, (event) => {
812
- emitReplaceAt(path, event.detail);
815
+ ${listen(ViraDropdown.events.selectedValuesChange, (event) => {
816
+ emitReplaceAt(path, assertWrap.isDefined(event.detail[0]));
813
817
  })}
814
- ></${ViraSelect}>
818
+ ></${ViraDropdown}>
815
819
  `
816
820
  : html `
817
821
  <${ViraInput.assign({
@@ -839,15 +843,15 @@ export const ViraJsonForm = defineViraElement()({
839
843
  return html `
840
844
  <div class="json-value-with-switcher">
841
845
  <span class="json-value-editor-slot">${editor}</span>
842
- <${ViraSelect.assign({
846
+ <${ViraDropdown.assign({
843
847
  options: modeOptions,
844
- value: mode,
848
+ selected: toSelectedValues(mode),
845
849
  })}
846
850
  title="Choose from options or enter a custom value"
847
- ${listen(ViraSelect.events.valueChange, (event) => {
848
- setStringMode(pathKey, event.detail);
851
+ ${listen(ViraDropdown.events.selectedValuesChange, (event) => {
852
+ setStringMode(pathKey, assertWrap.isDefined(event.detail[0]));
849
853
  })}
850
- ></${ViraSelect}>
854
+ ></${ViraDropdown}>
851
855
  </div>
852
856
  `;
853
857
  }
@@ -894,16 +898,16 @@ export const ViraJsonForm = defineViraElement()({
894
898
  return html `
895
899
  <div class="json-value-with-switcher">
896
900
  <span class="json-value-editor-slot">${editor}</span>
897
- <${ViraSelect.assign({
901
+ <${ViraDropdown.assign({
898
902
  options: switcherOptions,
899
- value: switcherSelected,
903
+ selected: toSelectedValues(switcherSelected),
900
904
  })}
901
905
  title="Change type"
902
- ${listen(ViraSelect.events.valueChange, (event) => {
903
- const newType = event.detail;
906
+ ${listen(ViraDropdown.events.selectedValuesChange, (event) => {
907
+ const newType = assertWrap.isDefined(event.detail[0]);
904
908
  emitReplaceAt(path, createDefaultForJsonType(newType));
905
909
  })}
906
- ></${ViraSelect}>
910
+ ></${ViraDropdown}>
907
911
  </div>
908
912
  `;
909
913
  }
@@ -9,7 +9,7 @@ import { noNativeFormStyles, noNativeSpacing } from '../styles/native-styles.js'
9
9
  import { viraShadows } from '../styles/shadows.js';
10
10
  import { viraTheme } from '../styles/vira-color-theme.js';
11
11
  import { defineViraElement } from '../util/define-vira-element.js';
12
- import { isMouseEventOnScrollbar } from '../util/pop-up-manager.js';
12
+ import { isMouseEventOnScrollbar } from '../util/popover-manager.js';
13
13
  import { ViraIcon } from './vira-icon.element.js';
14
14
  const globalEventsToCloseModalOn = [
15
15
  'pagehide',
@@ -3,7 +3,7 @@ import { type FullSpaRoute, type GenericTreePaths, type SpaRouter } from 'spa-ro
3
3
  import { type ViraIconSvg } from '../icons/icon-svg.js';
4
4
  import { ViraColorVariant } from '../styles/form-variants.js';
5
5
  import { ViraThemeColorName } from '../styles/vira-color-theme-object.js';
6
- import { type HorizontalAnchor, type PopUpOffset } from './pop-up/vira-pop-up-trigger.element.js';
6
+ import { type PopoverOffset } from './popover/vira-popover-trigger.element.js';
7
7
  /**
8
8
  * Controls which edge of the tab the selection indicator bar appears on.
9
9
  *
@@ -93,16 +93,10 @@ export declare const ViraTabs: import("element-vir").DeclarativeElementDefinitio
93
93
  * @default ViraTabsIconLayout.Vertical
94
94
  */
95
95
  iconLayout: ViraTabsIconLayout;
96
- /**
97
- * Horizontal anchor for the dropdown menu. Only used when tabs overflow into a dropdown.
98
- *
99
- * @default HorizontalAnchor.Left
100
- */
101
- menuHorizontalAnchor: HorizontalAnchor;
102
96
  /** Whether the dropdown trigger is disabled. Only used when tabs overflow into a dropdown. */
103
97
  menuIsDisabled: boolean;
104
- /** Offset for the dropdown pop-up. Only used when tabs overflow into a dropdown. */
105
- menuPopUpOffset: Readonly<PopUpOffset>;
98
+ /** Offset for the dropdown popover. Only used when tabs overflow into a dropdown. */
99
+ menuPopoverOffset: Readonly<PopoverOffset>;
106
100
  /**
107
101
  * Text shown on the overflow "more" trigger when the selected tab is _not_ collapsed into
108
102
  * the menu. When the selected tab _is_ collapsed, the trigger shows that tab's label (with
@@ -13,9 +13,9 @@ import { standaloneThemeColorNames, ViraColorVariant, viraColorVariantToHostClas
13
13
  import { noNativeFormStyles, noUserSelect, viraDisabledStyles, viraTheme } from '../styles/index.js';
14
14
  import { viraThemeByKeys, ViraThemeColorName } from '../styles/vira-color-theme-object.js';
15
15
  import { defineViraElement } from '../util/define-vira-element.js';
16
- import { renderMenuItemEntries } from '../util/pop-up-helpers.js';
17
- import { ViraMenuTrigger } from './pop-up/vira-menu-trigger.element.js';
18
- import { ViraMenuCornerStyle } from './pop-up/vira-menu.element.js';
16
+ import { renderMenuItemEntries } from '../util/menu-helpers.js';
17
+ import { ViraMenuTrigger } from './popover/vira-menu-trigger.element.js';
18
+ import { ViraMenuCornerStyle } from './popover/vira-menu.element.js';
19
19
  import { ViraBoldText } from './vira-bold-text.element.js';
20
20
  import { ViraButton } from './vira-button.element.js';
21
21
  import { ViraIcon } from './vira-icon.element.js';
@@ -786,10 +786,9 @@ export const ViraTabs = defineViraElement()({
786
786
  ? html `
787
787
  <div class="tab-more">
788
788
  <${ViraMenuTrigger.assign({
789
- horizontalAnchor: inputs.menuHorizontalAnchor,
790
789
  isDisabled: inputs.menuIsDisabled,
791
- popUpOffset: inputs.menuPopUpOffset,
792
- menuCornerStyle: ViraMenuCornerStyle.AllRounded,
790
+ popoverOffset: inputs.menuPopoverOffset,
791
+ menuCornerStyle: ViraMenuCornerStyle.Round,
793
792
  })}>
794
793
  <${ViraButton.assign({
795
794
  text: selectedIsCollapsed ? selectedTab?.label : overflowLabel,
@@ -75,21 +75,21 @@ export const ViraThemeSwitcher = defineViraElement()({
75
75
  const themeClient = inputs.themeClient || state.internalThemeClient || new ViraThemeClient();
76
76
  updateState({
77
77
  internalThemeClient: themeClient,
78
- currentTheme: themeClient.currentTheme,
78
+ currentTheme: themeClient.getCurrentTheme(),
79
79
  });
80
80
  const labels = inputs.labels || defaultThemeLabels;
81
81
  return Object.values(ViraThemeSelection).map((theme) => {
82
82
  return html `
83
83
  <button
84
84
  class=${classMap({
85
- selected: themeClient.currentTheme === theme,
85
+ selected: themeClient.getCurrentTheme() === theme,
86
86
  })}
87
87
  title=${labels[theme]}
88
88
  ${listen('click', (event) => {
89
89
  event.stopPropagation();
90
90
  themeClient.setSelectedTheme(theme);
91
91
  updateState({
92
- currentTheme: themeClient.currentTheme,
92
+ currentTheme: themeClient.getCurrentTheme(),
93
93
  });
94
94
  })}
95
95
  >
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './directives/index.js';
1
2
  export * from './elements/index.js';
2
3
  export * from './icons/index.js';
3
4
  export * from './styles/index.js';
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ export * from './directives/index.js';
1
2
  export * from './elements/index.js';
2
3
  export * from './icons/index.js';
3
4
  export * from './styles/index.js';
@@ -0,0 +1,40 @@
1
+ import { type PartialWithUndefined } from '@augment-vir/common';
2
+ import { type CSSResult } from 'element-vir';
3
+ /**
4
+ * The class that `PopoverManager` toggles on a popover to make the browser re-run its
5
+ * `position-try-fallbacks` from the first entry.
6
+ *
7
+ * @category Internal
8
+ */
9
+ export declare const anchoredPopoverRetryClass = "retry-position";
10
+ /**
11
+ * A single `position-try-fallbacks` entry for {@link createAnchoredPopoverStyles}.
12
+ *
13
+ * @category Popover
14
+ */
15
+ export type AnchoredPopoverFallback = {
16
+ /**
17
+ * The `@position-try` rule name, without the leading `--`. Only needs to be unique within the
18
+ * shadow root that the styles are used in.
19
+ */
20
+ name: string;
21
+ /** Only the properties that `@position-try` rules accept have any effect here. */
22
+ styles: CSSResult;
23
+ } & PartialWithUndefined<{
24
+ /** Adds `flip-block` to this entry, which mirrors it (and its block margins) vertically. */
25
+ flipBlock: boolean;
26
+ }>;
27
+ /**
28
+ * Creates the shared styles for a `popover` element that is positioned with CSS anchor positioning
29
+ * and opened through `PopoverManager`. Put the popover's default position (such as `position-area`)
30
+ * in a rule _after_ these styles. `fallbacks` are tried in order whenever the default position
31
+ * overflows the viewport.
32
+ *
33
+ * @category Popover
34
+ */
35
+ export declare function createAnchoredPopoverStyles({ selector, fallbacks, }: Readonly<{
36
+ fallbacks: ReadonlyArray<Readonly<AnchoredPopoverFallback>>;
37
+ } & PartialWithUndefined<{
38
+ /** Selects the popover element. Omit this when the host element itself is the popover. */
39
+ selector: CSSResult | string;
40
+ }>>): CSSResult;
@@ -0,0 +1,70 @@
1
+ import { css, unsafeCSS } from 'element-vir';
2
+ /**
3
+ * The class that `PopoverManager` toggles on a popover to make the browser re-run its
4
+ * `position-try-fallbacks` from the first entry.
5
+ *
6
+ * @category Internal
7
+ */
8
+ export const anchoredPopoverRetryClass = 'retry-position';
9
+ function createFallbackEntry({ name, flipBlock }) {
10
+ return flipBlock ? `--${name} flip-block` : `--${name}`;
11
+ }
12
+ /**
13
+ * Creates the shared styles for a `popover` element that is positioned with CSS anchor positioning
14
+ * and opened through `PopoverManager`. Put the popover's default position (such as `position-area`)
15
+ * in a rule _after_ these styles. `fallbacks` are tried in order whenever the default position
16
+ * overflows the viewport.
17
+ *
18
+ * @category Popover
19
+ */
20
+ export function createAnchoredPopoverStyles({ selector, fallbacks, }) {
21
+ const fallbackEntries = fallbacks.map((fallback) => createFallbackEntry(fallback));
22
+ const retryClass = unsafeCSS(anchoredPopoverRetryClass);
23
+ return css `
24
+ /*
25
+ Anchored through showPopover({source}).
26
+ */
27
+ ${selector ? unsafeCSS(selector) : unsafeCSS(':host')} {
28
+ /*
29
+ position-anchor is set explicitly because its initial value differs between browsers.
30
+ */
31
+ position-anchor: auto;
32
+ /* Override the browser's default popover styles. */
33
+ position: fixed;
34
+ inset: auto;
35
+ margin: 0;
36
+ padding: 0;
37
+ border: none;
38
+ height: auto;
39
+ overflow: visible;
40
+ background: none;
41
+ color: inherit;
42
+
43
+ position-try-fallbacks: ${unsafeCSS(fallbackEntries.join(', ') || 'none')};
44
+ }
45
+
46
+ /*
47
+ Browsers keep using the last position-try-fallbacks entry that fit until it no longer
48
+ fits, even when an earlier entry fits again, so without this the popover would not return
49
+ to its default position after a resize or scroll. Changing the computed
50
+ position-try-fallbacks value is what makes browsers start over from the first entry, so
51
+ this repeats an entry, which does not change the result.
52
+ */
53
+ ${selector
54
+ ? css `
55
+ ${unsafeCSS(selector)}.${retryClass}
56
+ `
57
+ : unsafeCSS(`:host(.${anchoredPopoverRetryClass})`)} {
58
+ position-try-fallbacks: ${unsafeCSS([
59
+ ...fallbackEntries,
60
+ ...fallbackEntries.slice(-1),
61
+ ].join(', ') || 'none')};
62
+ }
63
+
64
+ ${unsafeCSS(fallbacks
65
+ .map(({ name, styles }) => {
66
+ return `@position-try --${name} {${styles.cssText}}`;
67
+ })
68
+ .join('\n'))}
69
+ `;
70
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Checks if every non-whitespace character of `search` appears in `text`, in order, ignoring case.
3
+ * An empty `search` matches everything.
4
+ *
5
+ * @category Internal
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * fuzzyMatch({search: 'opa', text: 'Option A'}); // true
10
+ * fuzzyMatch({search: 'apo', text: 'Option A'}); // false
11
+ * ```
12
+ */
13
+ export declare function fuzzyMatch({ search, text, }: Readonly<{
14
+ search: string;
15
+ text: string;
16
+ }>): boolean;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Checks if every non-whitespace character of `search` appears in `text`, in order, ignoring case.
3
+ * An empty `search` matches everything.
4
+ *
5
+ * @category Internal
6
+ * @example
7
+ *
8
+ * ```ts
9
+ * fuzzyMatch({search: 'opa', text: 'Option A'}); // true
10
+ * fuzzyMatch({search: 'apo', text: 'Option A'}); // false
11
+ * ```
12
+ */
13
+ export function fuzzyMatch({ search, text, }) {
14
+ const lowerText = text.toLowerCase();
15
+ return (search
16
+ .replaceAll(/\s/g, '')
17
+ .toLowerCase()
18
+ .split('')
19
+ .reduce((textIndex, character) => {
20
+ return textIndex < 0
21
+ ? textIndex
22
+ : lowerText.indexOf(character, textIndex) + 1 || -1;
23
+ }, 0) >= 0);
24
+ }
@@ -1,11 +1,13 @@
1
+ export * from './anchored-popover.js';
1
2
  export * from './define-table.js';
2
3
  export * from './define-vira-element.js';
3
4
  export * from './dynamic-element.js';
5
+ export * from './fuzzy-match.js';
6
+ export * from './menu-helpers.js';
4
7
  export * from './overflow-observer.js';
5
- export * from './pop-up-helpers.js';
6
- export * from './pop-up-manager.js';
8
+ export * from './popover-manager.js';
7
9
  export * from './shared-text-input-logic.js';
10
+ export * from './vira-dropdown-option.js';
8
11
  export * from './vira-form-fields.js';
9
12
  export * from './vira-json-schema.js';
10
- export * from './vira-select-option.js';
11
13
  export * from './vira-theme-client.js';
@@ -1,11 +1,13 @@
1
+ export * from './anchored-popover.js';
1
2
  export * from './define-table.js';
2
3
  export * from './define-vira-element.js';
3
4
  export * from './dynamic-element.js';
5
+ export * from './fuzzy-match.js';
6
+ export * from './menu-helpers.js';
4
7
  export * from './overflow-observer.js';
5
- export * from './pop-up-helpers.js';
6
- export * from './pop-up-manager.js';
8
+ export * from './popover-manager.js';
7
9
  export * from './shared-text-input-logic.js';
10
+ export * from './vira-dropdown-option.js';
8
11
  export * from './vira-form-fields.js';
9
12
  export * from './vira-json-schema.js';
10
- export * from './vira-select-option.js';
11
13
  export * from './vira-theme-client.js';
@@ -1,7 +1,7 @@
1
1
  import { type MaybePromise, type PartialWithUndefined } from '@augment-vir/common';
2
+ import { type NavController } from 'device-navigation';
2
3
  import { type HtmlInterpolation } from 'element-vir';
3
- import { ViraMenuItem } from '../elements/pop-up/vira-menu-item.element.js';
4
- import { type PopUpManager, type PopUpManagerOptions, type ShowPopUpResult } from './pop-up-manager.js';
4
+ import { ViraMenuItem } from '../elements/popover/vira-menu-item.element.js';
5
5
  /**
6
6
  * Verifies that all items have unique ids.
7
7
  *
@@ -10,23 +10,10 @@ import { type PopUpManager, type PopUpManagerOptions, type ShowPopUpResult } fro
10
10
  export declare function assertUniqueIdProps(items: ReadonlyArray<Readonly<{
11
11
  id: PropertyKey;
12
12
  }>>): void;
13
- /**
14
- * Handles toggling pop up state for `ViraDropdown`.
15
- *
16
- * @category Internal
17
- */
18
- export declare function triggerPopUpState({ open, callback, popUpManager, host, options, }: Readonly<{
19
- open: boolean;
20
- popUpManager: PopUpManager;
21
- host: HTMLElement;
22
- } & PartialWithUndefined<{
23
- callback?: ((showPopUpResult: ShowPopUpResult | undefined) => void) | undefined;
24
- options?: Partial<PopUpManagerOptions> | undefined;
25
- }>>): void;
26
13
  /**
27
14
  * A helper type to be used with {@link renderMenuItemEntries}.
28
15
  *
29
- * @category PopUp
16
+ * @category Popover
30
17
  */
31
18
  export type ViraMenuItemEntry = {
32
19
  content: HtmlInterpolation;
@@ -44,7 +31,7 @@ export type ViraMenuItemEntry = {
44
31
  /**
45
32
  * A callback for menu items getting activated, to be used with {@link renderMenuItemEntries}.
46
33
  *
47
- * @category PopUp
34
+ * @category Popover
48
35
  */
49
36
  export type MenuItemClickCallback = (params: Readonly<{
50
37
  /** The menu item's index in the array. */
@@ -54,6 +41,8 @@ export type MenuItemClickCallback = (params: Readonly<{
54
41
  /**
55
42
  * A helper for rendering a bunch of menu items.
56
43
  *
57
- * @category PopUp
44
+ * @category Popover
58
45
  */
59
- export declare function renderMenuItemEntries(items: ReadonlyArray<Readonly<ViraMenuItemEntry>>): import("lit-html").HTMLTemplateResult[];
46
+ export declare function renderMenuItemEntries(items: ReadonlyArray<Readonly<ViraMenuItemEntry>>,
47
+ /** Enables arrow key navigation between the menu items. */
48
+ navController?: NavController | undefined): import("lit-html").HTMLTemplateResult[];
@@ -1,6 +1,7 @@
1
1
  import { filterMap, joinWithFinalConjunction, } from '@augment-vir/common';
2
- import { html, listen } from 'element-vir';
3
- import { ViraMenuItem } from '../elements/pop-up/vira-menu-item.element.js';
2
+ import { nav } from 'device-navigation';
3
+ import { html, listen, nothing } from 'element-vir';
4
+ import { ViraMenuItem } from '../elements/popover/vira-menu-item.element.js';
4
5
  /**
5
6
  * Verifies that all items have unique ids.
6
7
  *
@@ -21,32 +22,24 @@ export function assertUniqueIdProps(items) {
21
22
  throw new Error(`Duplicate option ids were given: ${joinWithFinalConjunction(duplicateIds)}`);
22
23
  }
23
24
  }
24
- /**
25
- * Handles toggling pop up state for `ViraDropdown`.
26
- *
27
- * @category Internal
28
- */
29
- export function triggerPopUpState({ open, callback, popUpManager, host, options, }) {
30
- if (open) {
31
- const showPopUpResult = popUpManager.showPopUp(host, options);
32
- callback?.(showPopUpResult);
33
- }
34
- else {
35
- popUpManager.removePopUp();
36
- callback?.(undefined);
37
- }
38
- }
39
25
  /**
40
26
  * A helper for rendering a bunch of menu items.
41
27
  *
42
- * @category PopUp
28
+ * @category Popover
43
29
  */
44
- export function renderMenuItemEntries(items) {
30
+ export function renderMenuItemEntries(items,
31
+ /** Enables arrow key navigation between the menu items. */
32
+ navController) {
45
33
  return filterMap(items, (item, index) => {
46
34
  return html `
47
35
  <${ViraMenuItem.assign({
48
36
  ...item,
49
37
  })}
38
+ ${navController
39
+ ? nav(navController, {
40
+ disabled: item.disabled,
41
+ })
42
+ : nothing}
50
43
  ${listen('click', async (event) => {
51
44
  if (item.disabled) {
52
45
  event.stopImmediatePropagation();