vira 32.4.0 → 33.0.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 (56) 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 +3 -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 +49 -0
  18. package/dist/elements/popover/vira-popover-trigger.element.js +301 -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 +28 -12
  23. package/dist/elements/vira-dropdown.element.js +172 -59
  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/index.d.ts +4 -3
  35. package/dist/util/index.js +4 -3
  36. package/dist/util/{pop-up-helpers.d.ts → menu-helpers.d.ts} +4 -18
  37. package/dist/util/{pop-up-helpers.js → menu-helpers.js} +2 -17
  38. package/dist/util/popover-manager.d.ts +123 -0
  39. package/dist/util/popover-manager.js +412 -0
  40. package/dist/util/vira-dropdown-option.d.ts +30 -0
  41. package/dist/util/vira-dropdown-option.js +8 -0
  42. package/dist/util/vira-form-fields.d.ts +2 -2
  43. package/dist/util/vira-theme-client.d.ts +1 -1
  44. package/dist/util/vira-theme-client.js +3 -3
  45. package/package.json +2 -1
  46. package/dist/elements/pop-up/vira-menu-trigger.element.d.ts +0 -45
  47. package/dist/elements/pop-up/vira-menu.element.d.ts +0 -36
  48. package/dist/elements/pop-up/vira-menu.element.js +0 -88
  49. package/dist/elements/pop-up/vira-pop-up-trigger.element.d.ts +0 -109
  50. package/dist/elements/pop-up/vira-pop-up-trigger.element.js +0 -408
  51. package/dist/elements/vira-select.element.d.ts +0 -44
  52. package/dist/elements/vira-select.element.js +0 -418
  53. package/dist/util/pop-up-manager.d.ts +0 -200
  54. package/dist/util/pop-up-manager.js +0 -258
  55. package/dist/util/vira-select-option.d.ts +0 -31
  56. 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
+ }
@@ -1,11 +1,12 @@
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 './menu-helpers.js';
4
6
  export * from './overflow-observer.js';
5
- export * from './pop-up-helpers.js';
6
- export * from './pop-up-manager.js';
7
+ export * from './popover-manager.js';
7
8
  export * from './shared-text-input-logic.js';
9
+ export * from './vira-dropdown-option.js';
8
10
  export * from './vira-form-fields.js';
9
11
  export * from './vira-json-schema.js';
10
- export * from './vira-select-option.js';
11
12
  export * from './vira-theme-client.js';
@@ -1,11 +1,12 @@
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 './menu-helpers.js';
4
6
  export * from './overflow-observer.js';
5
- export * from './pop-up-helpers.js';
6
- export * from './pop-up-manager.js';
7
+ export * from './popover-manager.js';
7
8
  export * from './shared-text-input-logic.js';
9
+ export * from './vira-dropdown-option.js';
8
10
  export * from './vira-form-fields.js';
9
11
  export * from './vira-json-schema.js';
10
- export * from './vira-select-option.js';
11
12
  export * from './vira-theme-client.js';
@@ -1,7 +1,6 @@
1
1
  import { type MaybePromise, type PartialWithUndefined } from '@augment-vir/common';
2
2
  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';
3
+ import { ViraMenuItem } from '../elements/popover/vira-menu-item.element.js';
5
4
  /**
6
5
  * Verifies that all items have unique ids.
7
6
  *
@@ -10,23 +9,10 @@ import { type PopUpManager, type PopUpManagerOptions, type ShowPopUpResult } fro
10
9
  export declare function assertUniqueIdProps(items: ReadonlyArray<Readonly<{
11
10
  id: PropertyKey;
12
11
  }>>): 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
12
  /**
27
13
  * A helper type to be used with {@link renderMenuItemEntries}.
28
14
  *
29
- * @category PopUp
15
+ * @category Popover
30
16
  */
31
17
  export type ViraMenuItemEntry = {
32
18
  content: HtmlInterpolation;
@@ -44,7 +30,7 @@ export type ViraMenuItemEntry = {
44
30
  /**
45
31
  * A callback for menu items getting activated, to be used with {@link renderMenuItemEntries}.
46
32
  *
47
- * @category PopUp
33
+ * @category Popover
48
34
  */
49
35
  export type MenuItemClickCallback = (params: Readonly<{
50
36
  /** The menu item's index in the array. */
@@ -54,6 +40,6 @@ export type MenuItemClickCallback = (params: Readonly<{
54
40
  /**
55
41
  * A helper for rendering a bunch of menu items.
56
42
  *
57
- * @category PopUp
43
+ * @category Popover
58
44
  */
59
45
  export declare function renderMenuItemEntries(items: ReadonlyArray<Readonly<ViraMenuItemEntry>>): import("lit-html").HTMLTemplateResult[];
@@ -1,6 +1,6 @@
1
1
  import { filterMap, joinWithFinalConjunction, } from '@augment-vir/common';
2
2
  import { html, listen } from 'element-vir';
3
- import { ViraMenuItem } from '../elements/pop-up/vira-menu-item.element.js';
3
+ import { ViraMenuItem } from '../elements/popover/vira-menu-item.element.js';
4
4
  /**
5
5
  * Verifies that all items have unique ids.
6
6
  *
@@ -21,25 +21,10 @@ export function assertUniqueIdProps(items) {
21
21
  throw new Error(`Duplicate option ids were given: ${joinWithFinalConjunction(duplicateIds)}`);
22
22
  }
23
23
  }
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
24
  /**
40
25
  * A helper for rendering a bunch of menu items.
41
26
  *
42
- * @category PopUp
27
+ * @category Popover
43
28
  */
44
29
  export function renderMenuItemEntries(items) {
45
30
  return filterMap(items, (item, index) => {
@@ -0,0 +1,123 @@
1
+ import { type PartialWithUndefined } from '@augment-vir/common';
2
+ import { type AnyDuration } from 'date-vir';
3
+ import { type Coords, type NavController } from 'device-navigation';
4
+ /**
5
+ * Used to prevent popovers from closing when a text input is active.
6
+ *
7
+ * @category Internal
8
+ */
9
+ export declare function isInputLikeElement(element: Element): boolean;
10
+ /**
11
+ * Whether a keyboard click (a click with `detail` of `0`) came from pressing Enter in a text input,
12
+ * which browsers turn into a click on the form's first button.
13
+ *
14
+ * @category Internal
15
+ */
16
+ export declare function isTextInputActive(): boolean;
17
+ /**
18
+ * Determines if a mouse event landed on a scrollbar rather than on element content. Scrollbar
19
+ * interactions fire mouse events on the scrolling element itself (or on `<html>` for the page
20
+ * scrollbar), so an outside-click check would otherwise treat dragging a scrollbar as a click away
21
+ * from the popover and dismiss it mid-drag.
22
+ *
23
+ * @category Internal
24
+ */
25
+ export declare function isMouseEventOnScrollbar(event: Readonly<MouseEvent>): boolean;
26
+ /**
27
+ * The interaction on the anchor element that shows and hides a popover.
28
+ *
29
+ * @category Popover
30
+ */
31
+ export declare enum PopoverTrigger {
32
+ /**
33
+ * Shows the popover shortly after the anchor is hovered or focused and hides it when the anchor
34
+ * is no longer hovered or focused.
35
+ */
36
+ Hover = "hover",
37
+ /** Toggles the popover when the anchor is clicked. An arrow key opens it. */
38
+ Click = "click",
39
+ /**
40
+ * Toggles the popover as soon as the mouse is pressed on the anchor, so it can be dragged over
41
+ * the popover's contents and released on one of them. Keyboard clicks and arrow keys also
42
+ * work.
43
+ */
44
+ Mousedown = "mousedown"
45
+ }
46
+ /**
47
+ * Options for {@link PopoverManager.update}, usually passed through the `popover` directive.
48
+ *
49
+ * @category Popover
50
+ */
51
+ export type PopoverOptions = {
52
+ /** `true` or `false` force the popover open or closed, ignoring all interactions. */
53
+ trigger: boolean | PopoverTrigger;
54
+ /**
55
+ * Returns the `popover` element to open. Called each time the popover opens, so it may create
56
+ * the element.
57
+ */
58
+ getPopover: () => HTMLElement;
59
+ } & PartialWithUndefined<{
60
+ /** Called when the user selects an item in the popover through the `NavController`. */
61
+ onNavSelect: (coords: Coords) => void;
62
+ /**
63
+ * How long to wait after the popover is triggered before opening it. Defaults to 300
64
+ * milliseconds for {@link PopoverTrigger.Hover} and no delay for everything else.
65
+ */
66
+ delay: AnyDuration;
67
+ /** Closes the popover once it has been open this long. By default it stays open. */
68
+ timeout: AnyDuration;
69
+ }>;
70
+ /**
71
+ * Opens and closes a single `popover` element that is anchored to another element: it opens the
72
+ * popover in response to the anchor's interactions (see {@link PopoverTrigger}) and closes it on
73
+ * Escape, an outside mousedown, or the page going inactive. Style the popover with
74
+ * `createAnchoredPopoverStyles`.
75
+ *
76
+ * @category Popover
77
+ */
78
+ export declare class PopoverManager {
79
+ /**
80
+ * Enables arrow key navigation within the open popover. Omit this for popovers that have
81
+ * nothing to navigate, like tooltips.
82
+ */
83
+ readonly navController?: NavController | undefined;
84
+ protected anchor: HTMLElement | undefined;
85
+ protected options: Readonly<PopoverOptions> | undefined;
86
+ /** The most recently opened popover. */
87
+ protected popover: HTMLElement | undefined;
88
+ protected showTimeout: ReturnType<typeof setTimeout> | undefined;
89
+ /** Closes the popover after `options.timeout`. */
90
+ protected hideTimeout: ReturnType<typeof setTimeout> | undefined;
91
+ /** Removes the listeners for the current anchor and `trigger`. */
92
+ protected removeAnchorListeners: (() => void) | undefined;
93
+ /** Removes the global listeners attached while the popover is open. */
94
+ protected removeOpenListeners: (() => void) | undefined;
95
+ constructor(
96
+ /**
97
+ * Enables arrow key navigation within the open popover. Omit this for popovers that have
98
+ * nothing to navigate, like tooltips.
99
+ */
100
+ navController?: NavController | undefined);
101
+ /** Whether the popover is open. */
102
+ isOpen(): boolean;
103
+ /** Call this each time the anchor or options might have changed. The `popover` directive does. */
104
+ update(anchor: HTMLElement, options: Readonly<PopoverOptions>): void;
105
+ /** Opens or closes the popover when `trigger` is `true` or `false`. */
106
+ applyForcedState(): void;
107
+ /** Opens the popover right away. */
108
+ show(): void;
109
+ /** Closes the popover, unless `trigger` forces it open, and cancels a scheduled show. */
110
+ hide(): void;
111
+ /** Opens the popover after `options.delay`. */
112
+ scheduleShow(): void;
113
+ /** Opens the popover, or closes it (and cancels a delayed open). */
114
+ toggle(): void;
115
+ /** Opens a closed popover when an arrow key is pressed. */
116
+ openOnArrow(event: Readonly<KeyboardEvent>): void;
117
+ /** Closes the popover and removes all listeners. */
118
+ destroy(): void;
119
+ /** Closes the popover even when `trigger` forces it open. */
120
+ close(): void;
121
+ /** Attaches the global listeners that only matter while the popover is open. */
122
+ protected attachOpenListeners(): () => void;
123
+ }