mood-ui 0.11.0 → 0.12.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.
- package/dist/components/data-display/calendar/AgendaView.cjs.map +1 -1
- package/dist/components/data-display/calendar/AgendaView.mjs.map +1 -1
- package/dist/components/data-display/calendar/AgendaView.vue_vue_type_script_setup_true_lang.cjs +4 -1
- package/dist/components/data-display/calendar/AgendaView.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/calendar/AgendaView.vue_vue_type_script_setup_true_lang.mjs +4 -1
- package/dist/components/data-display/calendar/AgendaView.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/calendar/DayView.cjs.map +1 -1
- package/dist/components/data-display/calendar/DayView.mjs.map +1 -1
- package/dist/components/data-display/calendar/DayView.vue_vue_type_script_setup_true_lang.cjs +7 -4
- package/dist/components/data-display/calendar/DayView.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/calendar/DayView.vue_vue_type_script_setup_true_lang.mjs +7 -4
- package/dist/components/data-display/calendar/DayView.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/calendar/MonthView.cjs +1 -1
- package/dist/components/data-display/calendar/MonthView.cjs.map +1 -1
- package/dist/components/data-display/calendar/MonthView.mjs +1 -1
- package/dist/components/data-display/calendar/MonthView.mjs.map +1 -1
- package/dist/components/data-display/calendar/MonthView.vue_vue_type_script_setup_true_lang.cjs +8 -12
- package/dist/components/data-display/calendar/MonthView.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/calendar/MonthView.vue_vue_type_script_setup_true_lang.mjs +8 -12
- package/dist/components/data-display/calendar/MonthView.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/calendar/Scheduler.cjs.map +1 -1
- package/dist/components/data-display/calendar/Scheduler.mjs.map +1 -1
- package/dist/components/data-display/calendar/Scheduler.vue_vue_type_script_setup_true_lang.cjs +7 -4
- package/dist/components/data-display/calendar/Scheduler.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/calendar/Scheduler.vue_vue_type_script_setup_true_lang.mjs +7 -4
- package/dist/components/data-display/calendar/Scheduler.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/calendar/WeekView.cjs.map +1 -1
- package/dist/components/data-display/calendar/WeekView.mjs.map +1 -1
- package/dist/components/data-display/calendar/WeekView.vue_vue_type_script_setup_true_lang.cjs +7 -4
- package/dist/components/data-display/calendar/WeekView.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/calendar/WeekView.vue_vue_type_script_setup_true_lang.mjs +7 -4
- package/dist/components/data-display/calendar/WeekView.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/data-display/date-picker/DateTimePicker.cjs.map +1 -1
- package/dist/components/data-display/date-picker/DateTimePicker.mjs.map +1 -1
- package/dist/components/data-display/date-picker/DateTimePicker.vue_vue_type_script_setup_true_lang.cjs +1 -1
- package/dist/components/data-display/date-picker/DateTimePicker.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/data-display/date-picker/DateTimePicker.vue_vue_type_script_setup_true_lang.mjs +1 -1
- package/dist/components/data-display/date-picker/DateTimePicker.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/feedback/Drawer.cjs.map +1 -1
- package/dist/components/feedback/Drawer.mjs.map +1 -1
- package/dist/components/feedback/Drawer.vue_vue_type_script_setup_true_lang.cjs +4 -9
- package/dist/components/feedback/Drawer.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/feedback/Drawer.vue_vue_type_script_setup_true_lang.mjs +4 -9
- package/dist/components/feedback/Drawer.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/feedback/Modal.cjs.map +1 -1
- package/dist/components/feedback/Modal.mjs.map +1 -1
- package/dist/components/feedback/Modal.vue_vue_type_script_setup_true_lang.cjs +4 -9
- package/dist/components/feedback/Modal.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/feedback/Modal.vue_vue_type_script_setup_true_lang.mjs +4 -9
- package/dist/components/feedback/Modal.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/feedback/Tooltip.cjs.map +1 -1
- package/dist/components/feedback/Tooltip.mjs.map +1 -1
- package/dist/components/feedback/Tooltip.vue_vue_type_script_setup_true_lang.cjs +44 -17
- package/dist/components/feedback/Tooltip.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/feedback/Tooltip.vue_vue_type_script_setup_true_lang.mjs +44 -17
- package/dist/components/feedback/Tooltip.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/Combobox.cjs.map +1 -1
- package/dist/components/forms/Combobox.mjs.map +1 -1
- package/dist/components/forms/Combobox.vue_vue_type_script_setup_true_lang.cjs +2 -2
- package/dist/components/forms/Combobox.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/Combobox.vue_vue_type_script_setup_true_lang.mjs +2 -2
- package/dist/components/forms/Combobox.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/PhoneInput.cjs.map +1 -1
- package/dist/components/forms/PhoneInput.mjs.map +1 -1
- package/dist/components/forms/PhoneInput.vue_vue_type_script_setup_true_lang.cjs +6 -1
- package/dist/components/forms/PhoneInput.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/PhoneInput.vue_vue_type_script_setup_true_lang.mjs +6 -1
- package/dist/components/forms/PhoneInput.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/forms/SearchInput.cjs.map +1 -1
- package/dist/components/forms/SearchInput.mjs.map +1 -1
- package/dist/components/forms/SearchInput.vue_vue_type_script_setup_true_lang.cjs +8 -6
- package/dist/components/forms/SearchInput.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/forms/SearchInput.vue_vue_type_script_setup_true_lang.mjs +8 -6
- package/dist/components/forms/SearchInput.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/layout/PopoverPanel.cjs +1 -1
- package/dist/components/layout/PopoverPanel.cjs.map +1 -1
- package/dist/components/layout/PopoverPanel.mjs +1 -1
- package/dist/components/layout/PopoverPanel.mjs.map +1 -1
- package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.cjs +2 -2
- package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.mjs +2 -2
- package/dist/components/layout/PopoverPanel.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/components/navigation/Switcher.cjs.map +1 -1
- package/dist/components/navigation/Switcher.mjs.map +1 -1
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.cjs +38 -40
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.cjs.map +1 -1
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.mjs +38 -40
- package/dist/components/navigation/Switcher.vue_vue_type_script_setup_true_lang.mjs.map +1 -1
- package/dist/composables/eventColors.cjs +51 -27
- package/dist/composables/eventColors.cjs.map +1 -1
- package/dist/composables/eventColors.mjs +51 -27
- package/dist/composables/eventColors.mjs.map +1 -1
- package/dist/composables/useBodyScrollLock.cjs +44 -0
- package/dist/composables/useBodyScrollLock.cjs.map +1 -0
- package/dist/composables/useBodyScrollLock.mjs +43 -0
- package/dist/composables/useBodyScrollLock.mjs.map +1 -0
- package/dist/composables/useCalendarTheme.cjs +29 -8
- package/dist/composables/useCalendarTheme.cjs.map +1 -1
- package/dist/composables/useCalendarTheme.mjs +29 -8
- package/dist/composables/useCalendarTheme.mjs.map +1 -1
- package/dist/composables/usePopover.cjs +44 -12
- package/dist/composables/usePopover.cjs.map +1 -1
- package/dist/composables/usePopover.mjs +44 -12
- package/dist/composables/usePopover.mjs.map +1 -1
- package/dist/mood-ui.css +9 -9
- package/dist/types/composables/eventColors.d.ts +2 -2
- package/dist/types/composables/useBodyScrollLock.d.ts +19 -0
- package/dist/types/composables/useCalendarTheme.d.ts +2 -0
- package/dist/types/interfaces/data-display/calendar/AgendaView.interface.d.ts +5 -0
- package/dist/types/interfaces/data-display/calendar/DayView.interface.d.ts +5 -0
- package/dist/types/interfaces/data-display/calendar/MonthView.interface.d.ts +5 -0
- package/dist/types/interfaces/data-display/calendar/Scheduler.interface.d.ts +5 -0
- package/dist/types/interfaces/data-display/calendar/WeekView.interface.d.ts +5 -0
- package/dist/types/utils/cssLength.d.ts +5 -0
- package/dist/types/utils/tooltipArrow.d.ts +34 -0
- package/dist/utils/cssLength.cjs +13 -0
- package/dist/utils/cssLength.cjs.map +1 -0
- package/dist/utils/cssLength.mjs +13 -0
- package/dist/utils/cssLength.mjs.map +1 -0
- package/dist/utils/tooltipArrow.cjs +37 -0
- package/dist/utils/tooltipArrow.cjs.map +1 -0
- package/dist/utils/tooltipArrow.mjs +36 -0
- package/dist/utils/tooltipArrow.mjs.map +1 -0
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCalendarTheme.mjs","names":[],"sources":["../../src/composables/useCalendarTheme.ts"],"sourcesContent":["import { computed, type ComputedRef } from 'vue'; \nimport { useModoConfig } from './useModoConfig'; \n \nexport type CalendarColor = 'default' | 'primary' | 'danger' | 'success' | 'warning'; \nexport type CalendarRadius = 'none' | 'small' | 'medium' | 'large' | 'full'; \nexport type DayNameCase = 'upper' | 'lower' | 'capitalize' | 'normal'; \n \nexport interface CalendarThemeInput { \n color: () => CalendarColor | undefined; \n radius: () => CalendarRadius | undefined; \n dayNameCase?: () => DayNameCase; \n} \n \nexport interface CalendarTheme { \n todayTextClass: ComputedRef<string>; \n todayBgClass: ComputedRef<string>; \n rangeSelectClass: ComputedRef<string>; \n focusRingColorClass: ComputedRef<string>; \n highlightDotClass: ComputedRef<string>; \n containerRadiusClass: ComputedRef<string>; \n eventRadiusClass: ComputedRef<string
|
|
1
|
+
{"version":3,"file":"useCalendarTheme.mjs","names":[],"sources":["../../src/composables/useCalendarTheme.ts"],"sourcesContent":["import { computed, type ComputedRef } from 'vue'; \nimport { useModoConfig } from './useModoConfig'; \n \nexport type CalendarColor = 'default' | 'primary' | 'danger' | 'success' | 'warning'; \nexport type CalendarRadius = 'none' | 'small' | 'medium' | 'large' | 'full'; \nexport type DayNameCase = 'upper' | 'lower' | 'capitalize' | 'normal'; \n \nexport interface CalendarThemeInput { \n color: () => CalendarColor | undefined; \n radius: () => CalendarRadius | undefined; \n dayNameCase?: () => DayNameCase; \n} \n \nexport interface CalendarTheme { \n todayTextClass: ComputedRef<string>; \n todayBgClass: ComputedRef<string>; \n rangeSelectClass: ComputedRef<string>; \n focusRingColorClass: ComputedRef<string>; \n highlightDotClass: ComputedRef<string>; \n containerRadiusClass: ComputedRef<string>; \n eventRadiusClass: ComputedRef<string>;\n /** Whether an event's left colour rule reads as a bar at the current radius. */\n showEventAccent: ComputedRef<boolean>;\n pillRadiusClass: ComputedRef<string>;\n dayNameCaseClass: ComputedRef<string>; \n resolvedColor: ComputedRef<CalendarColor>; \n} \n \nconst TEXT: Record<CalendarColor, string> = { \n default: 'text-foreground', \n primary: 'text-primary', \n danger: 'text-destructive', \n success: 'text-success', \n warning: 'text-warning', \n}; \n \nconst BG: Record<CalendarColor, string> = { \n default: 'bg-foreground text-background', \n primary: 'bg-primary text-primary-foreground', \n danger: 'bg-destructive text-destructive-foreground', \n success: 'bg-success text-success-foreground', \n warning: 'bg-warning text-warning-foreground', \n}; \n \nconst RANGE: Record<CalendarColor, string> = { \n default: 'border-foreground/40 bg-foreground/10', \n primary: 'border-primary/50 bg-primary/10', \n danger: 'border-destructive/50 bg-destructive/10', \n success: 'border-success/50 bg-success/10', \n warning: 'border-warning/50 bg-warning/10', \n}; \n \nconst RING: Record<CalendarColor, string> = { \n default: 'ring-ring', \n primary: 'ring-primary', \n danger: 'ring-destructive', \n success: 'ring-success', \n warning: 'ring-warning', \n}; \n \nconst DOT: Record<CalendarColor, string> = { \n default: 'bg-muted-foreground', \n primary: 'bg-primary', \n danger: 'bg-destructive', \n success: 'bg-success', \n warning: 'bg-warning', \n}; \n \nconst CONTAINER: Record<CalendarRadius, string> = { \n none: 'rounded-none', \n small: 'rounded', \n medium: 'rounded-md', \n large: 'rounded-xl', \n full: 'rounded-3xl', \n}; \n \nconst EVENT: Record<CalendarRadius, string> = { \n none: 'rounded-none', \n small: 'rounded-sm', \n medium: 'rounded', \n large: 'rounded-md', \n full: 'rounded-xl', \n}; \n \nconst PILL: Record<CalendarRadius, string> = { \n none: 'rounded-none', \n small: 'rounded-sm', \n medium: 'rounded-md', \n large: 'rounded-full', \n full: 'rounded-full', \n}; \n \n/**\n * Radii at which an event still has enough straight left edge to carry the\n * colour rule. Past these, `border-radius` sweeps the one-sided border around\n * the corner arc and it renders as a crescent hugging the side of the event\n * instead of a bar; the translucent fill and the text colour carry the event\n * colour on their own there.\n */\nconst EVENT_ACCENT_RADII: CalendarRadius[] = ['none', 'small', 'medium'];\n\nconst DAY_NAME_CASE: Record<DayNameCase, string> = {\n upper: 'uppercase', \n lower: 'lowercase', \n capitalize: 'capitalize', \n normal: 'normal-case', \n}; \n \nexport function useCalendarTheme(input: CalendarThemeInput): CalendarTheme { \n const cfg = useModoConfig(); \n const resolvedColor = computed<CalendarColor>(() => { \n const local = input.color(); \n if (local && local !== 'default') return local; \n return (cfg?.value.color as CalendarColor) ?? 'default'; \n }); \n const resolvedRadius = computed<CalendarRadius>(() => { \n const local = input.radius(); \n return local ?? (cfg?.value.radius as CalendarRadius) ?? 'medium'; \n }); \n \n const todayTextClass = computed(() => TEXT[resolvedColor.value] ?? TEXT.default); \n const todayBgClass = computed(() => BG[resolvedColor.value] ?? BG.default); \n const rangeSelectClass = computed(() => RANGE[resolvedColor.value] ?? RANGE.default); \n const focusRingColorClass = computed(() => RING[resolvedColor.value] ?? RING.default); \n const highlightDotClass = computed(() => DOT[resolvedColor.value] ?? DOT.default); \n const containerRadiusClass = computed(() => CONTAINER[resolvedRadius.value] ?? CONTAINER.large); \n const eventRadiusClass = computed(() => EVENT[resolvedRadius.value] ?? EVENT.small); \n const pillRadiusClass = computed(() => PILL[resolvedRadius.value] ?? PILL.full);\n const showEventAccent = computed(() => EVENT_ACCENT_RADII.includes(resolvedRadius.value));\n const dayNameCaseClass = computed(() => DAY_NAME_CASE[input.dayNameCase?.() ?? 'upper'] ?? DAY_NAME_CASE.upper); \n \n return { \n todayTextClass, \n todayBgClass, \n rangeSelectClass, \n focusRingColorClass, \n highlightDotClass, \n containerRadiusClass,\n eventRadiusClass,\n showEventAccent,\n pillRadiusClass,\n dayNameCaseClass, \n resolvedColor, \n }; \n}\n"],"mappings":";;;AA4BA,IAAM,OAAsC;CACxC,SAAS;CACT,SAAS;CACT,QAAQ;CACR,SAAS;CACT,SAAS;CACZ;AAED,IAAM,KAAoC;CACtC,SAAS;CACT,SAAS;CACT,QAAQ;CACR,SAAS;CACT,SAAS;CACZ;AAED,IAAM,QAAuC;CACzC,SAAS;CACT,SAAS;CACT,QAAQ;CACR,SAAS;CACT,SAAS;CACZ;AAED,IAAM,OAAsC;CACxC,SAAS;CACT,SAAS;CACT,QAAQ;CACR,SAAS;CACT,SAAS;CACZ;AAED,IAAM,MAAqC;CACvC,SAAS;CACT,SAAS;CACT,QAAQ;CACR,SAAS;CACT,SAAS;CACZ;AAED,IAAM,YAA4C;CAC9C,MAAM;CACN,OAAO;CACP,QAAQ;CACR,OAAO;CACP,MAAM;CACT;AAED,IAAM,QAAwC;CAC1C,MAAM;CACN,OAAO;CACP,QAAQ;CACR,OAAO;CACP,MAAM;CACT;AAED,IAAM,OAAuC;CACzC,MAAM;CACN,OAAO;CACP,QAAQ;CACR,OAAO;CACP,MAAM;CACT;;;;;;;;AASD,IAAM,qBAAuC;CAAC;CAAQ;CAAS;CAAS;AAExE,IAAM,gBAA6C;CAC/C,OAAO;CACP,OAAO;CACP,YAAY;CACZ,QAAQ;CACX;AAED,SAAgB,iBAAiB,OAA0C;CACvE,MAAM,MAAM,eAAe;CAC3B,MAAM,gBAAgB,eAA8B;EAChD,MAAM,QAAQ,MAAM,OAAO;EAC3B,IAAI,SAAS,UAAU,WAAW,OAAO;EACzC,OAAQ,KAAK,MAAM,SAA2B;GAChD;CACF,MAAM,iBAAiB,eAA+B;EAElD,OADc,MAAM,QACb,IAAU,KAAK,MAAM,UAA6B;GAC3D;CAEF,MAAM,iBAAiB,eAAe,KAAK,cAAc,UAAU,KAAK,QAAQ;CAChF,MAAM,eAAe,eAAe,GAAG,cAAc,UAAU,GAAG,QAAQ;CAC1E,MAAM,mBAAmB,eAAe,MAAM,cAAc,UAAU,MAAM,QAAQ;CACpF,MAAM,sBAAsB,eAAe,KAAK,cAAc,UAAU,KAAK,QAAQ;CACrF,MAAM,oBAAoB,eAAe,IAAI,cAAc,UAAU,IAAI,QAAQ;CACjF,MAAM,uBAAuB,eAAe,UAAU,eAAe,UAAU,UAAU,MAAM;CAC/F,MAAM,mBAAmB,eAAe,MAAM,eAAe,UAAU,MAAM,MAAM;CACnF,MAAM,kBAAkB,eAAe,KAAK,eAAe,UAAU,KAAK,KAAK;CAI/E,OAAO;EACH;EACA;EACA;EACA;EACA;EACA;EACA;EACA,iBAXoB,eAAe,mBAAmB,SAAS,eAAe,MAAM,CAWpF;EACA;EACA,kBAZqB,eAAe,cAAc,MAAM,eAAe,IAAI,YAAY,cAAc,MAYrG;EACA;EACH"}
|
|
@@ -1,8 +1,29 @@
|
|
|
1
1
|
require("../_virtual/_rolldown/runtime.cjs");
|
|
2
2
|
let vue = require("vue");
|
|
3
3
|
//#region src/composables/usePopover.ts
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
4
|
+
/**
|
|
5
|
+
* Floor for the viewport cap. A trigger sitting a few pixels from the bottom
|
|
6
|
+
* edge would otherwise get a panel too short to show anything; below this we
|
|
7
|
+
* let the panel keep its own scroll instead.
|
|
8
|
+
*/
|
|
9
|
+
var MIN_PANEL_HEIGHT = 120;
|
|
10
|
+
/**
|
|
11
|
+
* Content height of a panel, independent of any `max-height` we have already
|
|
12
|
+
* applied to it. `getBoundingClientRect()` reports the *constrained* height
|
|
13
|
+
* once capped, so it can't be used to decide whether the panel still needs a
|
|
14
|
+
* cap. The panel clips vertically and its inner wrapper is the scroll
|
|
15
|
+
* container, so that wrapper's `scrollHeight` (plus the panel's own vertical
|
|
16
|
+
* borders) is the height the panel would take if nothing constrained it.
|
|
17
|
+
*/
|
|
18
|
+
function naturalHeight(panel) {
|
|
19
|
+
const inner = panel.firstElementChild;
|
|
20
|
+
if (!inner) return panel.getBoundingClientRect().height;
|
|
21
|
+
const styles = getComputedStyle(panel);
|
|
22
|
+
const borders = Number.parseFloat(styles.borderTopWidth || "0") + Number.parseFloat(styles.borderBottomWidth || "0");
|
|
23
|
+
return Math.max(inner.scrollHeight + borders, panel.getBoundingClientRect().height);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Headless composable para lógica de popover/dropdown:
|
|
6
27
|
* - estado abierto/cerrado
|
|
7
28
|
* - click outside + Escape
|
|
8
29
|
* - posición absoluta relativa al viewport (para usar con `position: fixed`)
|
|
@@ -40,9 +61,8 @@ function usePopover(options = {}) {
|
|
|
40
61
|
const initialPlacement = (0, vue.toValue)(placementOption);
|
|
41
62
|
const matchTriggerWidth = (0, vue.toValue)(matchTriggerWidthOption);
|
|
42
63
|
const tRect = trigger.getBoundingClientRect();
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
const panelH = pRect?.height ?? 0;
|
|
64
|
+
const panelW = (panel?.getBoundingClientRect())?.width ?? tRect.width;
|
|
65
|
+
const panelH = panel ? naturalHeight(panel) : 0;
|
|
46
66
|
const vw = window.innerWidth;
|
|
47
67
|
const vh = window.innerHeight;
|
|
48
68
|
const margin = 8;
|
|
@@ -56,22 +76,23 @@ function usePopover(options = {}) {
|
|
|
56
76
|
}
|
|
57
77
|
const isBottom = resolved.startsWith("bottom");
|
|
58
78
|
const align = resolved.split("-")[1];
|
|
59
|
-
|
|
79
|
+
const availableH = isBottom ? vh - margin - (tRect.bottom + offset) : tRect.top - offset - margin;
|
|
80
|
+
const maxHeight = Math.max(Math.min(availableH, vh - margin * 2), MIN_PANEL_HEIGHT);
|
|
81
|
+
const renderedH = Math.min(panelH, maxHeight);
|
|
82
|
+
let top = isBottom ? tRect.bottom + offset : tRect.top - renderedH - offset;
|
|
60
83
|
let left;
|
|
61
84
|
if (align === "start") left = tRect.left;
|
|
62
85
|
else if (align === "end") left = tRect.right - panelW;
|
|
63
86
|
else left = tRect.left + tRect.width / 2 - panelW / 2;
|
|
64
87
|
if (left + panelW > vw - margin) left = vw - panelW - margin;
|
|
65
88
|
if (left < margin) left = margin;
|
|
66
|
-
|
|
67
|
-
const clampedMaxH = panelH > availableH ? Math.max(availableH, 120) : void 0;
|
|
68
|
-
if (top + panelH > vh - margin) top = Math.max(margin, vh - panelH - margin);
|
|
89
|
+
if (top + renderedH > vh - margin) top = Math.max(margin, vh - renderedH - margin);
|
|
69
90
|
if (top < margin) top = margin;
|
|
70
91
|
position.value = {
|
|
71
92
|
top,
|
|
72
93
|
left,
|
|
73
94
|
width: matchTriggerWidth ? tRect.width : void 0,
|
|
74
|
-
maxHeight
|
|
95
|
+
maxHeight,
|
|
75
96
|
placement: resolved
|
|
76
97
|
};
|
|
77
98
|
}
|
|
@@ -129,6 +150,17 @@ function usePopover(options = {}) {
|
|
|
129
150
|
close();
|
|
130
151
|
}
|
|
131
152
|
let resizeObserver = null;
|
|
153
|
+
/**
|
|
154
|
+
* Observe the panel *and* its scroll container. The panel itself stops
|
|
155
|
+
* changing size once it hits the viewport cap, so growing content (async
|
|
156
|
+
* search results, a longer list) would never notify us if we only watched
|
|
157
|
+
* the outer box.
|
|
158
|
+
*/
|
|
159
|
+
function observePanel(el) {
|
|
160
|
+
resizeObserver?.observe(el);
|
|
161
|
+
const inner = el.firstElementChild;
|
|
162
|
+
if (inner instanceof HTMLElement) resizeObserver?.observe(inner);
|
|
163
|
+
}
|
|
132
164
|
(0, vue.watch)(isOpen, (open) => {
|
|
133
165
|
if (open) {
|
|
134
166
|
document.addEventListener("pointerdown", onDocumentPointerDown, true);
|
|
@@ -138,7 +170,7 @@ function usePopover(options = {}) {
|
|
|
138
170
|
if (triggerRef.value && typeof ResizeObserver !== "undefined") {
|
|
139
171
|
resizeObserver = new ResizeObserver(onScrollOrResize);
|
|
140
172
|
resizeObserver.observe(triggerRef.value);
|
|
141
|
-
if (panelRef.value)
|
|
173
|
+
if (panelRef.value) observePanel(panelRef.value);
|
|
142
174
|
}
|
|
143
175
|
} else {
|
|
144
176
|
document.removeEventListener("pointerdown", onDocumentPointerDown, true);
|
|
@@ -150,7 +182,7 @@ function usePopover(options = {}) {
|
|
|
150
182
|
}
|
|
151
183
|
});
|
|
152
184
|
(0, vue.watch)(panelRef, (el) => {
|
|
153
|
-
if (isOpen.value && el && resizeObserver)
|
|
185
|
+
if (isOpen.value && el && resizeObserver) observePanel(el);
|
|
154
186
|
});
|
|
155
187
|
(0, vue.watch)(() => [(0, vue.toValue)(placementOption), (0, vue.toValue)(matchTriggerWidthOption)], () => {
|
|
156
188
|
if (isOpen.value) measure();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePopover.cjs","names":[],"sources":["../../src/composables/usePopover.ts"],"sourcesContent":["import { ref, computed, onBeforeUnmount, watch, toValue, type Ref, type MaybeRefOrGetter } from 'vue'; \n \nexport type PopoverPlacement = \n | 'bottom-start' | 'bottom-end' | 'bottom-center' \n | 'top-start' | 'top-end' | 'top-center'; \n \nexport interface UsePopoverOptions { \n /** Placement inicial. @default 'bottom-start' */ \n placement?: MaybeRefOrGetter<PopoverPlacement>; \n /** Offset vertical entre trigger y panel (px). @default 6 */ \n offset?: number; \n /** Auto-flip cuando no cabe en el viewport. @default true */ \n flip?: boolean; \n /** Hacer que el panel tenga el mismo ancho del trigger. @default false */ \n matchTriggerWidth?: MaybeRefOrGetter<boolean>; \n /** Cerrar al hacer click fuera del trigger y del panel. @default true */\n closeOnClickOutside?: boolean;\n /** Cerrar con Escape. @default true */\n closeOnEscape?: boolean;\n /**\n * Cerrar cuando la página hace scroll (fuera del panel). @default true\n * Con `false` el popover se reposiciona en vez de cerrarse — útil para un\n * dropdown de búsqueda que no debe desaparecer si enfocar el input provoca\n * un pequeño auto-scroll.\n */\n closeOnScroll?: boolean;\n /** Callback cuando se abre. */ \n onOpen?: () => void; \n /** Callback cuando se cierra. */ \n onClose?: () => void; \n} \n \nexport interface PopoverPosition {\n top: number;\n left: number;\n width?: number;\n maxHeight?: number;\n /** Placement final (puede diferir del solicitado si hubo flip). */\n placement: PopoverPlacement;\n} \n \n/** \n * Headless composable para lógica de popover/dropdown: \n * - estado abierto/cerrado \n * - click outside + Escape \n * - posición absoluta relativa al viewport (para usar con `position: fixed`) \n * - auto-flip vertical cuando no cabe \n * - reposicionado en scroll + resize + ResizeObserver del trigger \n * \n * El caller se encarga de renderizar el trigger y el panel; este composable \n * sólo devuelve refs y estado. \n */ \nexport function usePopover(options: UsePopoverOptions = {}) { \n const { \n placement: placementOption = 'bottom-start', \n offset = 6, \n flip = true, \n matchTriggerWidth: matchTriggerWidthOption = false, \n closeOnClickOutside = true,\n closeOnEscape = true,\n closeOnScroll = true,\n onOpen,\n onClose,\n } = options;\n \n const triggerRef = ref<HTMLElement | null>(null); \n const panelRef = ref<HTMLElement | null>(null); \n const isOpen = ref(false); \n \n const position = ref<PopoverPosition>({ \n top: 0, \n left: 0, \n placement: toValue(placementOption), \n }); \n \n const panelStyle = computed(() => {\n const style: Record<string, string> = {\n position: 'fixed',\n top: `${position.value.top}px`,\n left: `${position.value.left}px`,\n zIndex: '1300',\n };\n if (position.value.width !== undefined) {\n style.width = `${position.value.width}px`;\n }\n if (position.value.maxHeight !== undefined) {\n style.maxHeight = `${position.value.maxHeight}px`;\n }\n return style;\n }); \n \n function measure(): void { \n const trigger = triggerRef.value; \n const panel = panelRef.value; \n if (!trigger) return; \n \n const initialPlacement = toValue(placementOption); \n const matchTriggerWidth = toValue(matchTriggerWidthOption); \n \n const tRect = trigger.getBoundingClientRect(); \n const pRect = panel?.getBoundingClientRect(); \n const panelW = pRect?.width ?? tRect.width; \n const panelH = pRect?.height ?? 0; \n const vw = window.innerWidth; \n const vh = window.innerHeight; \n const margin = 8; \n \n let resolved: PopoverPlacement = initialPlacement; \n \n // Vertical flip check. \n if (flip) { \n const wantsTop = initialPlacement.startsWith('top'); \n const spaceBelow = vh - tRect.bottom - margin; \n const spaceAbove = tRect.top - margin; \n if (!wantsTop && spaceBelow < panelH && spaceAbove > spaceBelow) { \n resolved = initialPlacement.replace('bottom', 'top') as PopoverPlacement; \n } else if (wantsTop && spaceAbove < panelH && spaceBelow > spaceAbove) { \n resolved = initialPlacement.replace('top', 'bottom') as PopoverPlacement; \n } \n } \n \n const isBottom = resolved.startsWith('bottom'); \n const align = resolved.split('-')[1] as 'start' | 'end' | 'center'; \n \n let top = isBottom ? tRect.bottom + offset : tRect.top - panelH - offset; \n \n let left: number; \n if (align === 'start') left = tRect.left; \n else if (align === 'end') left = tRect.right - panelW; \n else left = tRect.left + tRect.width / 2 - panelW / 2; \n \n // Horizontal clamp (simple, sin variante de flip lateral). \n if (left + panelW > vw - margin) left = vw - panelW - margin; \n if (left < margin) left = margin; \n \n // Vertical clamp: if panel taller than available space, cap it so it stays in viewport.\n const availableH = isBottom\n ? vh - margin - (tRect.bottom + offset)\n : tRect.top - offset - margin;\n const clampedMaxH = panelH > availableH ? Math.max(availableH, 120) : undefined;\n\n if (top + panelH > vh - margin) top = Math.max(margin, vh - panelH - margin);\n if (top < margin) top = margin;\n\n position.value = {\n top,\n left,\n width: matchTriggerWidth ? tRect.width : undefined,\n maxHeight: clampedMaxH,\n placement: resolved,\n }; \n } \n \n /* ---------- API ---------- */ \n \n function open() { \n if (isOpen.value) return; \n isOpen.value = true; \n onOpen?.(); \n // Medir en el próximo frame, cuando el panel ya esté en el DOM. \n requestAnimationFrame(() => { \n measure(); \n // Segunda pasada para corregir si aparecieron scrollbars. \n requestAnimationFrame(measure); \n }); \n } \n \n function close() { \n if (!isOpen.value) return; \n isOpen.value = false; \n onClose?.(); \n } \n \n function toggle() { \n isOpen.value ? close() : open(); \n } \n \n /* ---------- Listeners ---------- */ \n \n function onDocumentPointerDown(e: PointerEvent) { \n if (!isOpen.value || !closeOnClickOutside) return; \n const target = e.target as Element | null; \n if (!target) return; \n if (triggerRef.value?.contains(target)) return; \n if (panelRef.value?.contains(target)) return; \n // Click landed inside a *different* popover (e.g. a Select's \n // dropdown teleported to <body> from a child of our panel). \n // Treat any click on a `.modo-popover` ancestor as \"inside\" so \n // nested popovers don't close their parent. The parent will be \n // closed normally when the user clicks truly outside. \n if (typeof (target as Element).closest === 'function' && (target as Element).closest('.modo-popover')) { \n return; \n } \n close(); \n } \n \n function onDocumentKeyDown(e: KeyboardEvent) { \n if (!isOpen.value) return; \n if (closeOnEscape && e.key === 'Escape') { \n e.preventDefault(); \n close(); \n triggerRef.value?.focus?.(); \n } \n } \n \n function onScrollOrResize() { \n if (isOpen.value) measure(); \n } \n \n /** \n * Scroll outside del panel → cerrar. Scroll dentro del panel (p. ej. lista \n * de opciones) → no hace nada. Scroll en window/body → cerrar. \n * Se usa el evento \"scroll\" con capture para recibir cualquier scroll. \n */ \n function onWindowScroll(e: Event) {\n if (!isOpen.value) return;\n const target = e.target as Node | null;\n if (target && panelRef.value && panelRef.value.contains(target)) {\n // Scroll interno del panel — ignorar.\n return;\n }\n // Scroll inside a nested popover (Select's option list teleported\n // to <body>) should not close us either.\n if (target instanceof Element && target.closest('.modo-popover')) {\n return;\n }\n // Reposition instead of closing when the caller opted out of scroll-close.\n if (!closeOnScroll) { measure(); return; }\n close();\n }\n \n let resizeObserver: ResizeObserver | null = null; \n \n watch(isOpen, (open) => { \n if (open) { \n document.addEventListener('pointerdown', onDocumentPointerDown, true); \n document.addEventListener('keydown', onDocumentKeyDown); \n // Scroll en cualquier contenedor (incluido window) cierra el popover \n // salvo si el scroll viene desde dentro del propio panel. \n window.addEventListener('scroll', onWindowScroll, true); \n window.addEventListener('resize', onScrollOrResize); \n if (triggerRef.value && typeof ResizeObserver !== 'undefined') { \n resizeObserver = new ResizeObserver(onScrollOrResize); \n resizeObserver.observe(triggerRef.value); \n if (panelRef.value) resizeObserver.observe(panelRef.value); \n } \n } else { \n document.removeEventListener('pointerdown', onDocumentPointerDown, true); \n document.removeEventListener('keydown', onDocumentKeyDown); \n window.removeEventListener('scroll', onWindowScroll, true); \n window.removeEventListener('resize', onScrollOrResize); \n resizeObserver?.disconnect(); \n resizeObserver = null; \n } \n }); \n \n // Si el panel se monta después de open, vincularlo al ResizeObserver. \n watch(panelRef, (el) => { \n if (isOpen.value && el && resizeObserver) resizeObserver.observe(el); \n }); \n \n // Re-measure when reactive placement / matchTriggerWidth options change \n // while the popover is open (allows playgrounds to switch placement live). \n watch( \n () => [toValue(placementOption), toValue(matchTriggerWidthOption)], \n () => { if (isOpen.value) measure(); }, \n ); \n \n onBeforeUnmount(() => { \n document.removeEventListener('pointerdown', onDocumentPointerDown, true); \n document.removeEventListener('keydown', onDocumentKeyDown); \n window.removeEventListener('scroll', onWindowScroll, true); \n window.removeEventListener('resize', onScrollOrResize); \n resizeObserver?.disconnect(); \n }); \n \n return { \n triggerRef: triggerRef as Ref<HTMLElement | null>, \n panelRef: panelRef as Ref<HTMLElement | null>, \n isOpen, \n position, \n panelStyle, \n open, \n close, \n toggle, \n measure, \n }; \n}\n"],"mappings":";;;;;;;;;;;;;;AAoDA,SAAgB,WAAW,UAA6B,EAAE,EAAE;CACxD,MAAM,EACF,WAAW,kBAAkB,gBAC7B,SAAS,GACT,OAAO,MACP,mBAAmB,0BAA0B,OAC7C,sBAAsB,MACtB,gBAAgB,MAChB,gBAAgB,MAChB,QACA,YACA;CAEJ,MAAM,cAAA,GAAA,IAAA,KAAqC,KAAK;CAChD,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IAAA,aACU,EAAA,GAAA,IAAA,SAAS,gBAAgB,GAAA,GAAA,IAAA,SAAU,wBAAwB,CAAC,QAC5D;EAAE,IAAI,OAAO,OAAO,SAAS;GACtC;CAED,CAAA,GAAA,IAAA,uBAAsB;EAClB,SAAS,oBAAoB,eAAe,uBAAuB,KAAK;EACxE,SAAS,oBAAoB,WAAW,kBAAkB;EAC1D,OAAO,oBAAoB,UAAU,gBAAgB,KAAK;EAC1D,OAAO,oBAAoB,UAAU,iBAAiB;EACtD,gBAAgB,YAAY;GAC9B;CAEF,OAAO;EACS;EACF;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACH"}
|
|
1
|
+
{"version":3,"file":"usePopover.cjs","names":[],"sources":["../../src/composables/usePopover.ts"],"sourcesContent":["import { ref, computed, onBeforeUnmount, watch, toValue, type Ref, type MaybeRefOrGetter } from 'vue'; \n \nexport type PopoverPlacement = \n | 'bottom-start' | 'bottom-end' | 'bottom-center' \n | 'top-start' | 'top-end' | 'top-center'; \n \nexport interface UsePopoverOptions { \n /** Placement inicial. @default 'bottom-start' */ \n placement?: MaybeRefOrGetter<PopoverPlacement>; \n /** Offset vertical entre trigger y panel (px). @default 6 */ \n offset?: number; \n /** Auto-flip cuando no cabe en el viewport. @default true */ \n flip?: boolean; \n /** Hacer que el panel tenga el mismo ancho del trigger. @default false */ \n matchTriggerWidth?: MaybeRefOrGetter<boolean>; \n /** Cerrar al hacer click fuera del trigger y del panel. @default true */\n closeOnClickOutside?: boolean;\n /** Cerrar con Escape. @default true */\n closeOnEscape?: boolean;\n /**\n * Cerrar cuando la página hace scroll (fuera del panel). @default true\n * Con `false` el popover se reposiciona en vez de cerrarse — útil para un\n * dropdown de búsqueda que no debe desaparecer si enfocar el input provoca\n * un pequeño auto-scroll.\n */\n closeOnScroll?: boolean;\n /** Callback cuando se abre. */ \n onOpen?: () => void; \n /** Callback cuando se cierra. */ \n onClose?: () => void; \n} \n \nexport interface PopoverPosition {\n top: number;\n left: number;\n width?: number;\n maxHeight?: number;\n /** Placement final (puede diferir del solicitado si hubo flip). */\n placement: PopoverPlacement;\n} \n \n/**\n * Floor for the viewport cap. A trigger sitting a few pixels from the bottom\n * edge would otherwise get a panel too short to show anything; below this we\n * let the panel keep its own scroll instead.\n */\nconst MIN_PANEL_HEIGHT = 120;\n\n/**\n * Content height of a panel, independent of any `max-height` we have already\n * applied to it. `getBoundingClientRect()` reports the *constrained* height\n * once capped, so it can't be used to decide whether the panel still needs a\n * cap. The panel clips vertically and its inner wrapper is the scroll\n * container, so that wrapper's `scrollHeight` (plus the panel's own vertical\n * borders) is the height the panel would take if nothing constrained it.\n */\nfunction naturalHeight(panel: HTMLElement): number {\n const inner = panel.firstElementChild as HTMLElement | null;\n if (!inner) return panel.getBoundingClientRect().height;\n const styles = getComputedStyle(panel);\n const borders =\n Number.parseFloat(styles.borderTopWidth || '0')\n + Number.parseFloat(styles.borderBottomWidth || '0');\n return Math.max(inner.scrollHeight + borders, panel.getBoundingClientRect().height);\n}\n\n/**\n * Headless composable para lógica de popover/dropdown:\n * - estado abierto/cerrado \n * - click outside + Escape \n * - posición absoluta relativa al viewport (para usar con `position: fixed`) \n * - auto-flip vertical cuando no cabe \n * - reposicionado en scroll + resize + ResizeObserver del trigger \n * \n * El caller se encarga de renderizar el trigger y el panel; este composable \n * sólo devuelve refs y estado. \n */ \nexport function usePopover(options: UsePopoverOptions = {}) { \n const { \n placement: placementOption = 'bottom-start', \n offset = 6, \n flip = true, \n matchTriggerWidth: matchTriggerWidthOption = false, \n closeOnClickOutside = true,\n closeOnEscape = true,\n closeOnScroll = true,\n onOpen,\n onClose,\n } = options;\n \n const triggerRef = ref<HTMLElement | null>(null); \n const panelRef = ref<HTMLElement | null>(null); \n const isOpen = ref(false); \n \n const position = ref<PopoverPosition>({ \n top: 0, \n left: 0, \n placement: toValue(placementOption), \n }); \n \n const panelStyle = computed(() => {\n const style: Record<string, string> = {\n position: 'fixed',\n top: `${position.value.top}px`,\n left: `${position.value.left}px`,\n zIndex: '1300',\n };\n if (position.value.width !== undefined) {\n style.width = `${position.value.width}px`;\n }\n if (position.value.maxHeight !== undefined) {\n style.maxHeight = `${position.value.maxHeight}px`;\n }\n return style;\n }); \n \n function measure(): void {\n const trigger = triggerRef.value;\n const panel = panelRef.value;\n if (!trigger) return;\n\n const initialPlacement = toValue(placementOption);\n const matchTriggerWidth = toValue(matchTriggerWidthOption);\n\n const tRect = trigger.getBoundingClientRect();\n const pRect = panel?.getBoundingClientRect();\n const panelW = pRect?.width ?? tRect.width;\n // Height the panel *wants*, ignoring any cap we applied on a previous\n // pass. The panel clips its own overflow, so its scroll container holds\n // the real content height — without this, once we cap the panel its\n // measured height equals the cap and every later decision (flip, fit)\n // would be made against our own constraint instead of the content.\n const panelH = panel ? naturalHeight(panel) : 0;\n const vw = window.innerWidth;\n const vh = window.innerHeight;\n const margin = 8;\n\n let resolved: PopoverPlacement = initialPlacement; \n \n // Vertical flip check. \n if (flip) { \n const wantsTop = initialPlacement.startsWith('top'); \n const spaceBelow = vh - tRect.bottom - margin; \n const spaceAbove = tRect.top - margin; \n if (!wantsTop && spaceBelow < panelH && spaceAbove > spaceBelow) { \n resolved = initialPlacement.replace('bottom', 'top') as PopoverPlacement; \n } else if (wantsTop && spaceAbove < panelH && spaceBelow > spaceAbove) { \n resolved = initialPlacement.replace('top', 'bottom') as PopoverPlacement; \n } \n } \n \n const isBottom = resolved.startsWith('bottom');\n const align = resolved.split('-')[1] as 'start' | 'end' | 'center';\n\n // Vertical clamp: the panel may never grow past the edge of the\n // viewport, so cap it to whatever room the resolved side leaves. This\n // is applied unconditionally — capping only when the panel currently\n // overflows would make the cap oscillate: capped panel measures as\n // \"fits\", cap drops, content grows back past the edge, repeat.\n const availableH = isBottom\n ? vh - margin - (tRect.bottom + offset)\n : tRect.top - offset - margin;\n // A trigger scrolled past the edge of the viewport reports space that\n // does not exist on screen (`closeOnScroll: false` keeps the popover\n // open in exactly that state), so the room on the chosen side is not\n // enough on its own — the panel can never be taller than the viewport.\n const maxHeight = Math.max(\n Math.min(availableH, vh - margin * 2),\n MIN_PANEL_HEIGHT,\n );\n const renderedH = Math.min(panelH, maxHeight);\n\n let top = isBottom ? tRect.bottom + offset : tRect.top - renderedH - offset;\n\n let left: number; \n if (align === 'start') left = tRect.left; \n else if (align === 'end') left = tRect.right - panelW; \n else left = tRect.left + tRect.width / 2 - panelW / 2; \n \n // Horizontal clamp (simple, sin variante de flip lateral). \n if (left + panelW > vw - margin) left = vw - panelW - margin; \n if (left < margin) left = margin; \n \n if (top + renderedH > vh - margin) top = Math.max(margin, vh - renderedH - margin);\n if (top < margin) top = margin;\n\n position.value = {\n top,\n left,\n width: matchTriggerWidth ? tRect.width : undefined,\n maxHeight,\n placement: resolved,\n };\n }\n\n /* ---------- API ---------- */ \n \n function open() { \n if (isOpen.value) return; \n isOpen.value = true; \n onOpen?.(); \n // Medir en el próximo frame, cuando el panel ya esté en el DOM. \n requestAnimationFrame(() => { \n measure(); \n // Segunda pasada para corregir si aparecieron scrollbars. \n requestAnimationFrame(measure); \n }); \n } \n \n function close() { \n if (!isOpen.value) return; \n isOpen.value = false; \n onClose?.(); \n } \n \n function toggle() { \n isOpen.value ? close() : open(); \n } \n \n /* ---------- Listeners ---------- */ \n \n function onDocumentPointerDown(e: PointerEvent) { \n if (!isOpen.value || !closeOnClickOutside) return; \n const target = e.target as Element | null; \n if (!target) return; \n if (triggerRef.value?.contains(target)) return; \n if (panelRef.value?.contains(target)) return; \n // Click landed inside a *different* popover (e.g. a Select's \n // dropdown teleported to <body> from a child of our panel). \n // Treat any click on a `.modo-popover` ancestor as \"inside\" so \n // nested popovers don't close their parent. The parent will be \n // closed normally when the user clicks truly outside. \n if (typeof (target as Element).closest === 'function' && (target as Element).closest('.modo-popover')) { \n return; \n } \n close(); \n } \n \n function onDocumentKeyDown(e: KeyboardEvent) { \n if (!isOpen.value) return; \n if (closeOnEscape && e.key === 'Escape') { \n e.preventDefault(); \n close(); \n triggerRef.value?.focus?.(); \n } \n } \n \n function onScrollOrResize() { \n if (isOpen.value) measure(); \n } \n \n /** \n * Scroll outside del panel → cerrar. Scroll dentro del panel (p. ej. lista \n * de opciones) → no hace nada. Scroll en window/body → cerrar. \n * Se usa el evento \"scroll\" con capture para recibir cualquier scroll. \n */ \n function onWindowScroll(e: Event) {\n if (!isOpen.value) return;\n const target = e.target as Node | null;\n if (target && panelRef.value && panelRef.value.contains(target)) {\n // Scroll interno del panel — ignorar.\n return;\n }\n // Scroll inside a nested popover (Select's option list teleported\n // to <body>) should not close us either.\n if (target instanceof Element && target.closest('.modo-popover')) {\n return;\n }\n // Reposition instead of closing when the caller opted out of scroll-close.\n if (!closeOnScroll) { measure(); return; }\n close();\n }\n \n let resizeObserver: ResizeObserver | null = null;\n\n /**\n * Observe the panel *and* its scroll container. The panel itself stops\n * changing size once it hits the viewport cap, so growing content (async\n * search results, a longer list) would never notify us if we only watched\n * the outer box.\n */\n function observePanel(el: HTMLElement): void {\n resizeObserver?.observe(el);\n const inner = el.firstElementChild;\n if (inner instanceof HTMLElement) resizeObserver?.observe(inner);\n }\n\n watch(isOpen, (open) => { \n if (open) { \n document.addEventListener('pointerdown', onDocumentPointerDown, true); \n document.addEventListener('keydown', onDocumentKeyDown); \n // Scroll en cualquier contenedor (incluido window) cierra el popover \n // salvo si el scroll viene desde dentro del propio panel. \n window.addEventListener('scroll', onWindowScroll, true); \n window.addEventListener('resize', onScrollOrResize); \n if (triggerRef.value && typeof ResizeObserver !== 'undefined') { \n resizeObserver = new ResizeObserver(onScrollOrResize);\n resizeObserver.observe(triggerRef.value);\n if (panelRef.value) observePanel(panelRef.value);\n }\n } else { \n document.removeEventListener('pointerdown', onDocumentPointerDown, true); \n document.removeEventListener('keydown', onDocumentKeyDown); \n window.removeEventListener('scroll', onWindowScroll, true); \n window.removeEventListener('resize', onScrollOrResize); \n resizeObserver?.disconnect(); \n resizeObserver = null; \n } \n }); \n \n // Si el panel se monta después de open, vincularlo al ResizeObserver. \n watch(panelRef, (el) => {\n if (isOpen.value && el && resizeObserver) observePanel(el);\n });\n \n // Re-measure when reactive placement / matchTriggerWidth options change \n // while the popover is open (allows playgrounds to switch placement live). \n watch( \n () => [toValue(placementOption), toValue(matchTriggerWidthOption)], \n () => { if (isOpen.value) measure(); }, \n ); \n \n onBeforeUnmount(() => { \n document.removeEventListener('pointerdown', onDocumentPointerDown, true); \n document.removeEventListener('keydown', onDocumentKeyDown); \n window.removeEventListener('scroll', onWindowScroll, true); \n window.removeEventListener('resize', onScrollOrResize); \n resizeObserver?.disconnect(); \n }); \n \n return { \n triggerRef: triggerRef as Ref<HTMLElement | null>, \n panelRef: panelRef as Ref<HTMLElement | null>, \n isOpen, \n position, \n panelStyle, \n open, \n close, \n toggle, \n measure, \n }; \n}\n"],"mappings":";;;;;;;;AA8CA,IAAM,mBAAmB;;;;;;;;;AAUzB,SAAS,cAAc,OAA4B;CAC/C,MAAM,QAAQ,MAAM;CACpB,IAAI,CAAC,OAAO,OAAO,MAAM,uBAAuB,CAAC;CACjD,MAAM,SAAS,iBAAiB,MAAM;CACtC,MAAM,UACF,OAAO,WAAW,OAAO,kBAAkB,IAAI,GAC7C,OAAO,WAAW,OAAO,qBAAqB,IAAI;CACxD,OAAO,KAAK,IAAI,MAAM,eAAe,SAAS,MAAM,uBAAuB,CAAC,OAAO;;;;;;;;;;;;;AAcvF,SAAgB,WAAW,UAA6B,EAAE,EAAE;CACxD,MAAM,EACF,WAAW,kBAAkB,gBAC7B,SAAS,GACT,OAAO,MACP,mBAAmB,0BAA0B,OAC7C,sBAAsB,MACtB,gBAAgB,MAChB,gBAAgB,MAChB,QACA,YACA;CAEJ,MAAM,cAAA,GAAA,IAAA,KAAqC,KAAK;CAChD,MAAM,YAAA,GAAA,IAAA,KAAmC,KAAK;CAC9C,MAAM,UAAA,GAAA,IAAA,KAAa,MAAM;CAEzB,MAAM,YAAA,GAAA,IAAA,KAAgC;EAClC,KAAK;EACL,MAAM;EACN,YAAA,GAAA,IAAA,SAAmB,gB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aACU,EAAA,GAAA,IAAA,SAAS,gBAAgB,GAAA,GAAA,IAAA,SAAU,wBAAwB,CAAC,QAC5D;EAAE,IAAI,OAAO,OAAO,SAAS;GACtC;CAED,CAAA,GAAA,IAAA,uBAAsB;EAClB,SAAS,oBAAoB,eAAe,uBAAuB,KAAK;EACxE,SAAS,oBAAoB,WAAW,kBAAkB;EAC1D,OAAO,oBAAoB,UAAU,gBAAgB,KAAK;EAC1D,OAAO,oBAAoB,UAAU,iBAAiB;EACtD,gBAAgB,YAAY;GAC9B;CAEF,OAAO;EACS;EACF;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACH"}
|
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
import { computed, onBeforeUnmount, ref, toValue, watch } from "vue";
|
|
2
2
|
//#region src/composables/usePopover.ts
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
3
|
+
/**
|
|
4
|
+
* Floor for the viewport cap. A trigger sitting a few pixels from the bottom
|
|
5
|
+
* edge would otherwise get a panel too short to show anything; below this we
|
|
6
|
+
* let the panel keep its own scroll instead.
|
|
7
|
+
*/
|
|
8
|
+
var MIN_PANEL_HEIGHT = 120;
|
|
9
|
+
/**
|
|
10
|
+
* Content height of a panel, independent of any `max-height` we have already
|
|
11
|
+
* applied to it. `getBoundingClientRect()` reports the *constrained* height
|
|
12
|
+
* once capped, so it can't be used to decide whether the panel still needs a
|
|
13
|
+
* cap. The panel clips vertically and its inner wrapper is the scroll
|
|
14
|
+
* container, so that wrapper's `scrollHeight` (plus the panel's own vertical
|
|
15
|
+
* borders) is the height the panel would take if nothing constrained it.
|
|
16
|
+
*/
|
|
17
|
+
function naturalHeight(panel) {
|
|
18
|
+
const inner = panel.firstElementChild;
|
|
19
|
+
if (!inner) return panel.getBoundingClientRect().height;
|
|
20
|
+
const styles = getComputedStyle(panel);
|
|
21
|
+
const borders = Number.parseFloat(styles.borderTopWidth || "0") + Number.parseFloat(styles.borderBottomWidth || "0");
|
|
22
|
+
return Math.max(inner.scrollHeight + borders, panel.getBoundingClientRect().height);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Headless composable para lógica de popover/dropdown:
|
|
5
26
|
* - estado abierto/cerrado
|
|
6
27
|
* - click outside + Escape
|
|
7
28
|
* - posición absoluta relativa al viewport (para usar con `position: fixed`)
|
|
@@ -39,9 +60,8 @@ function usePopover(options = {}) {
|
|
|
39
60
|
const initialPlacement = toValue(placementOption);
|
|
40
61
|
const matchTriggerWidth = toValue(matchTriggerWidthOption);
|
|
41
62
|
const tRect = trigger.getBoundingClientRect();
|
|
42
|
-
const
|
|
43
|
-
const
|
|
44
|
-
const panelH = pRect?.height ?? 0;
|
|
63
|
+
const panelW = (panel?.getBoundingClientRect())?.width ?? tRect.width;
|
|
64
|
+
const panelH = panel ? naturalHeight(panel) : 0;
|
|
45
65
|
const vw = window.innerWidth;
|
|
46
66
|
const vh = window.innerHeight;
|
|
47
67
|
const margin = 8;
|
|
@@ -55,22 +75,23 @@ function usePopover(options = {}) {
|
|
|
55
75
|
}
|
|
56
76
|
const isBottom = resolved.startsWith("bottom");
|
|
57
77
|
const align = resolved.split("-")[1];
|
|
58
|
-
|
|
78
|
+
const availableH = isBottom ? vh - margin - (tRect.bottom + offset) : tRect.top - offset - margin;
|
|
79
|
+
const maxHeight = Math.max(Math.min(availableH, vh - margin * 2), MIN_PANEL_HEIGHT);
|
|
80
|
+
const renderedH = Math.min(panelH, maxHeight);
|
|
81
|
+
let top = isBottom ? tRect.bottom + offset : tRect.top - renderedH - offset;
|
|
59
82
|
let left;
|
|
60
83
|
if (align === "start") left = tRect.left;
|
|
61
84
|
else if (align === "end") left = tRect.right - panelW;
|
|
62
85
|
else left = tRect.left + tRect.width / 2 - panelW / 2;
|
|
63
86
|
if (left + panelW > vw - margin) left = vw - panelW - margin;
|
|
64
87
|
if (left < margin) left = margin;
|
|
65
|
-
|
|
66
|
-
const clampedMaxH = panelH > availableH ? Math.max(availableH, 120) : void 0;
|
|
67
|
-
if (top + panelH > vh - margin) top = Math.max(margin, vh - panelH - margin);
|
|
88
|
+
if (top + renderedH > vh - margin) top = Math.max(margin, vh - renderedH - margin);
|
|
68
89
|
if (top < margin) top = margin;
|
|
69
90
|
position.value = {
|
|
70
91
|
top,
|
|
71
92
|
left,
|
|
72
93
|
width: matchTriggerWidth ? tRect.width : void 0,
|
|
73
|
-
maxHeight
|
|
94
|
+
maxHeight,
|
|
74
95
|
placement: resolved
|
|
75
96
|
};
|
|
76
97
|
}
|
|
@@ -128,6 +149,17 @@ function usePopover(options = {}) {
|
|
|
128
149
|
close();
|
|
129
150
|
}
|
|
130
151
|
let resizeObserver = null;
|
|
152
|
+
/**
|
|
153
|
+
* Observe the panel *and* its scroll container. The panel itself stops
|
|
154
|
+
* changing size once it hits the viewport cap, so growing content (async
|
|
155
|
+
* search results, a longer list) would never notify us if we only watched
|
|
156
|
+
* the outer box.
|
|
157
|
+
*/
|
|
158
|
+
function observePanel(el) {
|
|
159
|
+
resizeObserver?.observe(el);
|
|
160
|
+
const inner = el.firstElementChild;
|
|
161
|
+
if (inner instanceof HTMLElement) resizeObserver?.observe(inner);
|
|
162
|
+
}
|
|
131
163
|
watch(isOpen, (open) => {
|
|
132
164
|
if (open) {
|
|
133
165
|
document.addEventListener("pointerdown", onDocumentPointerDown, true);
|
|
@@ -137,7 +169,7 @@ function usePopover(options = {}) {
|
|
|
137
169
|
if (triggerRef.value && typeof ResizeObserver !== "undefined") {
|
|
138
170
|
resizeObserver = new ResizeObserver(onScrollOrResize);
|
|
139
171
|
resizeObserver.observe(triggerRef.value);
|
|
140
|
-
if (panelRef.value)
|
|
172
|
+
if (panelRef.value) observePanel(panelRef.value);
|
|
141
173
|
}
|
|
142
174
|
} else {
|
|
143
175
|
document.removeEventListener("pointerdown", onDocumentPointerDown, true);
|
|
@@ -149,7 +181,7 @@ function usePopover(options = {}) {
|
|
|
149
181
|
}
|
|
150
182
|
});
|
|
151
183
|
watch(panelRef, (el) => {
|
|
152
|
-
if (isOpen.value && el && resizeObserver)
|
|
184
|
+
if (isOpen.value && el && resizeObserver) observePanel(el);
|
|
153
185
|
});
|
|
154
186
|
watch(() => [toValue(placementOption), toValue(matchTriggerWidthOption)], () => {
|
|
155
187
|
if (isOpen.value) measure();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePopover.mjs","names":[],"sources":["../../src/composables/usePopover.ts"],"sourcesContent":["import { ref, computed, onBeforeUnmount, watch, toValue, type Ref, type MaybeRefOrGetter } from 'vue'; \n \nexport type PopoverPlacement = \n | 'bottom-start' | 'bottom-end' | 'bottom-center' \n | 'top-start' | 'top-end' | 'top-center'; \n \nexport interface UsePopoverOptions { \n /** Placement inicial. @default 'bottom-start' */ \n placement?: MaybeRefOrGetter<PopoverPlacement>; \n /** Offset vertical entre trigger y panel (px). @default 6 */ \n offset?: number; \n /** Auto-flip cuando no cabe en el viewport. @default true */ \n flip?: boolean; \n /** Hacer que el panel tenga el mismo ancho del trigger. @default false */ \n matchTriggerWidth?: MaybeRefOrGetter<boolean>; \n /** Cerrar al hacer click fuera del trigger y del panel. @default true */\n closeOnClickOutside?: boolean;\n /** Cerrar con Escape. @default true */\n closeOnEscape?: boolean;\n /**\n * Cerrar cuando la página hace scroll (fuera del panel). @default true\n * Con `false` el popover se reposiciona en vez de cerrarse — útil para un\n * dropdown de búsqueda que no debe desaparecer si enfocar el input provoca\n * un pequeño auto-scroll.\n */\n closeOnScroll?: boolean;\n /** Callback cuando se abre. */ \n onOpen?: () => void; \n /** Callback cuando se cierra. */ \n onClose?: () => void; \n} \n \nexport interface PopoverPosition {\n top: number;\n left: number;\n width?: number;\n maxHeight?: number;\n /** Placement final (puede diferir del solicitado si hubo flip). */\n placement: PopoverPlacement;\n} \n \n/** \n * Headless composable para lógica de popover/dropdown: \n * - estado abierto/cerrado \n * - click outside + Escape \n * - posición absoluta relativa al viewport (para usar con `position: fixed`) \n * - auto-flip vertical cuando no cabe \n * - reposicionado en scroll + resize + ResizeObserver del trigger \n * \n * El caller se encarga de renderizar el trigger y el panel; este composable \n * sólo devuelve refs y estado. \n */ \nexport function usePopover(options: UsePopoverOptions = {}) { \n const { \n placement: placementOption = 'bottom-start', \n offset = 6, \n flip = true, \n matchTriggerWidth: matchTriggerWidthOption = false, \n closeOnClickOutside = true,\n closeOnEscape = true,\n closeOnScroll = true,\n onOpen,\n onClose,\n } = options;\n \n const triggerRef = ref<HTMLElement | null>(null); \n const panelRef = ref<HTMLElement | null>(null); \n const isOpen = ref(false); \n \n const position = ref<PopoverPosition>({ \n top: 0, \n left: 0, \n placement: toValue(placementOption), \n }); \n \n const panelStyle = computed(() => {\n const style: Record<string, string> = {\n position: 'fixed',\n top: `${position.value.top}px`,\n left: `${position.value.left}px`,\n zIndex: '1300',\n };\n if (position.value.width !== undefined) {\n style.width = `${position.value.width}px`;\n }\n if (position.value.maxHeight !== undefined) {\n style.maxHeight = `${position.value.maxHeight}px`;\n }\n return style;\n }); \n \n function measure(): void { \n const trigger = triggerRef.value; \n const panel = panelRef.value; \n if (!trigger) return; \n \n const initialPlacement = toValue(placementOption); \n const matchTriggerWidth = toValue(matchTriggerWidthOption); \n \n const tRect = trigger.getBoundingClientRect(); \n const pRect = panel?.getBoundingClientRect(); \n const panelW = pRect?.width ?? tRect.width; \n const panelH = pRect?.height ?? 0; \n const vw = window.innerWidth; \n const vh = window.innerHeight; \n const margin = 8; \n \n let resolved: PopoverPlacement = initialPlacement; \n \n // Vertical flip check. \n if (flip) { \n const wantsTop = initialPlacement.startsWith('top'); \n const spaceBelow = vh - tRect.bottom - margin; \n const spaceAbove = tRect.top - margin; \n if (!wantsTop && spaceBelow < panelH && spaceAbove > spaceBelow) { \n resolved = initialPlacement.replace('bottom', 'top') as PopoverPlacement; \n } else if (wantsTop && spaceAbove < panelH && spaceBelow > spaceAbove) { \n resolved = initialPlacement.replace('top', 'bottom') as PopoverPlacement; \n } \n } \n \n const isBottom = resolved.startsWith('bottom'); \n const align = resolved.split('-')[1] as 'start' | 'end' | 'center'; \n \n let top = isBottom ? tRect.bottom + offset : tRect.top - panelH - offset; \n \n let left: number; \n if (align === 'start') left = tRect.left; \n else if (align === 'end') left = tRect.right - panelW; \n else left = tRect.left + tRect.width / 2 - panelW / 2; \n \n // Horizontal clamp (simple, sin variante de flip lateral). \n if (left + panelW > vw - margin) left = vw - panelW - margin; \n if (left < margin) left = margin; \n \n // Vertical clamp: if panel taller than available space, cap it so it stays in viewport.\n const availableH = isBottom\n ? vh - margin - (tRect.bottom + offset)\n : tRect.top - offset - margin;\n const clampedMaxH = panelH > availableH ? Math.max(availableH, 120) : undefined;\n\n if (top + panelH > vh - margin) top = Math.max(margin, vh - panelH - margin);\n if (top < margin) top = margin;\n\n position.value = {\n top,\n left,\n width: matchTriggerWidth ? tRect.width : undefined,\n maxHeight: clampedMaxH,\n placement: resolved,\n }; \n } \n \n /* ---------- API ---------- */ \n \n function open() { \n if (isOpen.value) return; \n isOpen.value = true; \n onOpen?.(); \n // Medir en el próximo frame, cuando el panel ya esté en el DOM. \n requestAnimationFrame(() => { \n measure(); \n // Segunda pasada para corregir si aparecieron scrollbars. \n requestAnimationFrame(measure); \n }); \n } \n \n function close() { \n if (!isOpen.value) return; \n isOpen.value = false; \n onClose?.(); \n } \n \n function toggle() { \n isOpen.value ? close() : open(); \n } \n \n /* ---------- Listeners ---------- */ \n \n function onDocumentPointerDown(e: PointerEvent) { \n if (!isOpen.value || !closeOnClickOutside) return; \n const target = e.target as Element | null; \n if (!target) return; \n if (triggerRef.value?.contains(target)) return; \n if (panelRef.value?.contains(target)) return; \n // Click landed inside a *different* popover (e.g. a Select's \n // dropdown teleported to <body> from a child of our panel). \n // Treat any click on a `.modo-popover` ancestor as \"inside\" so \n // nested popovers don't close their parent. The parent will be \n // closed normally when the user clicks truly outside. \n if (typeof (target as Element).closest === 'function' && (target as Element).closest('.modo-popover')) { \n return; \n } \n close(); \n } \n \n function onDocumentKeyDown(e: KeyboardEvent) { \n if (!isOpen.value) return; \n if (closeOnEscape && e.key === 'Escape') { \n e.preventDefault(); \n close(); \n triggerRef.value?.focus?.(); \n } \n } \n \n function onScrollOrResize() { \n if (isOpen.value) measure(); \n } \n \n /** \n * Scroll outside del panel → cerrar. Scroll dentro del panel (p. ej. lista \n * de opciones) → no hace nada. Scroll en window/body → cerrar. \n * Se usa el evento \"scroll\" con capture para recibir cualquier scroll. \n */ \n function onWindowScroll(e: Event) {\n if (!isOpen.value) return;\n const target = e.target as Node | null;\n if (target && panelRef.value && panelRef.value.contains(target)) {\n // Scroll interno del panel — ignorar.\n return;\n }\n // Scroll inside a nested popover (Select's option list teleported\n // to <body>) should not close us either.\n if (target instanceof Element && target.closest('.modo-popover')) {\n return;\n }\n // Reposition instead of closing when the caller opted out of scroll-close.\n if (!closeOnScroll) { measure(); return; }\n close();\n }\n \n let resizeObserver: ResizeObserver | null = null; \n \n watch(isOpen, (open) => { \n if (open) { \n document.addEventListener('pointerdown', onDocumentPointerDown, true); \n document.addEventListener('keydown', onDocumentKeyDown); \n // Scroll en cualquier contenedor (incluido window) cierra el popover \n // salvo si el scroll viene desde dentro del propio panel. \n window.addEventListener('scroll', onWindowScroll, true); \n window.addEventListener('resize', onScrollOrResize); \n if (triggerRef.value && typeof ResizeObserver !== 'undefined') { \n resizeObserver = new ResizeObserver(onScrollOrResize); \n resizeObserver.observe(triggerRef.value); \n if (panelRef.value) resizeObserver.observe(panelRef.value); \n } \n } else { \n document.removeEventListener('pointerdown', onDocumentPointerDown, true); \n document.removeEventListener('keydown', onDocumentKeyDown); \n window.removeEventListener('scroll', onWindowScroll, true); \n window.removeEventListener('resize', onScrollOrResize); \n resizeObserver?.disconnect(); \n resizeObserver = null; \n } \n }); \n \n // Si el panel se monta después de open, vincularlo al ResizeObserver. \n watch(panelRef, (el) => { \n if (isOpen.value && el && resizeObserver) resizeObserver.observe(el); \n }); \n \n // Re-measure when reactive placement / matchTriggerWidth options change \n // while the popover is open (allows playgrounds to switch placement live). \n watch( \n () => [toValue(placementOption), toValue(matchTriggerWidthOption)], \n () => { if (isOpen.value) measure(); }, \n ); \n \n onBeforeUnmount(() => { \n document.removeEventListener('pointerdown', onDocumentPointerDown, true); \n document.removeEventListener('keydown', onDocumentKeyDown); \n window.removeEventListener('scroll', onWindowScroll, true); \n window.removeEventListener('resize', onScrollOrResize); \n resizeObserver?.disconnect(); \n }); \n \n return { \n triggerRef: triggerRef as Ref<HTMLElement | null>, \n panelRef: panelRef as Ref<HTMLElement | null>, \n isOpen, \n position, \n panelStyle, \n open, \n close, \n toggle, \n measure, \n }; \n}\n"],"mappings":";;;;;;;;;;;;;AAoDA,SAAgB,WAAW,UAA6B,EAAE,EAAE;CACxD,MAAM,EACF,WAAW,kBAAkB,gBAC7B,SAAS,GACT,OAAO,MACP,mBAAmB,0BAA0B,OAC7C,sBAAsB,MACtB,gBAAgB,MAChB,gBAAgB,MAChB,QACA,YACA;CAEJ,MAAM,aAAa,IAAwB,KAAK;CAChD,MAAM,WAAW,IAAwB,KAAK;CAC9C,MAAM,SAAS,IAAI,MAAM;CAEzB,MAAM,WAAW,IAAqB;EAClC,KAAK;EACL,MAAM;EACN,WAAW,QAAQ,gBAAgB;EACtC,CAAC;CAEF,MAAM,aAAa,eAAe;EAC9B,MAAM,QAAgC;GAClC,UAAU;GACV,KAAK,GAAG,SAAS,MAAM,IAAI;GAC3B,MAAM,GAAG,SAAS,MAAM,KAAK;GAC7B,QAAQ;GACX;EACD,IAAI,SAAS,MAAM,UAAU,KAAA,GACzB,MAAM,QAAQ,GAAG,SAAS,MAAM,MAAM;EAE1C,IAAI,SAAS,MAAM,cAAc,KAAA,GAC7B,MAAM,YAAY,GAAG,SAAS,MAAM,UAAU;EAElD,OAAO;GACT;CAEF,SAAS,UAAgB;EACrB,MAAM,UAAU,WAAW;EAC3B,MAAM,QAAQ,SAAS;EACvB,IAAI,CAAC,SAAS;EAEd,MAAM,mBAAmB,QAAQ,gBAAgB;EACjD,MAAM,oBAAoB,QAAQ,wBAAwB;EAE1D,MAAM,QAAQ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AW,SAAS,OAAO,mBAAmB,aAAa;IAC3D,iBAAiB,IAAI,eAAe,iBAAiB;IACrD,eAAe,QAAQ,WAAW,MAAM;IACxC,IAAI,SAAS,OAAO,eAAe,QAAQ,SAAS,MAAM;;SAE3D;GACH,SAAS,oBAAoB,eAAe,uBAAuB,KAAK;GACxE,SAAS,oBAAoB,WAAW,kBAAkB;GAC1D,OAAO,oBAAoB,UAAU,gBAAgB,KAAK;GAC1D,OAAO,oBAAoB,UAAU,iBAAiB;GACtD,gBAAgB,YAAY;GAC5B,iBAAiB;;GAEvB;CAGF,MAAM,WAAW,OAAO;EACpB,IAAI,OAAO,SAAS,MAAM,gBAAgB,eAAe,QAAQ,GAAG;GACtE;CAIF,YACU,CAAC,QAAQ,gBAAgB,EAAE,QAAQ,wBAAwB,CAAC,QAC5D;EAAE,IAAI,OAAO,OAAO,SAAS;GACtC;CAED,sBAAsB;EAClB,SAAS,oBAAoB,eAAe,uBAAuB,KAAK;EACxE,SAAS,oBAAoB,WAAW,kBAAkB;EAC1D,OAAO,oBAAoB,UAAU,gBAAgB,KAAK;EAC1D,OAAO,oBAAoB,UAAU,iBAAiB;EACtD,gBAAgB,YAAY;GAC9B;CAEF,OAAO;EACS;EACF;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACH"}
|
|
1
|
+
{"version":3,"file":"usePopover.mjs","names":[],"sources":["../../src/composables/usePopover.ts"],"sourcesContent":["import { ref, computed, onBeforeUnmount, watch, toValue, type Ref, type MaybeRefOrGetter } from 'vue'; \n \nexport type PopoverPlacement = \n | 'bottom-start' | 'bottom-end' | 'bottom-center' \n | 'top-start' | 'top-end' | 'top-center'; \n \nexport interface UsePopoverOptions { \n /** Placement inicial. @default 'bottom-start' */ \n placement?: MaybeRefOrGetter<PopoverPlacement>; \n /** Offset vertical entre trigger y panel (px). @default 6 */ \n offset?: number; \n /** Auto-flip cuando no cabe en el viewport. @default true */ \n flip?: boolean; \n /** Hacer que el panel tenga el mismo ancho del trigger. @default false */ \n matchTriggerWidth?: MaybeRefOrGetter<boolean>; \n /** Cerrar al hacer click fuera del trigger y del panel. @default true */\n closeOnClickOutside?: boolean;\n /** Cerrar con Escape. @default true */\n closeOnEscape?: boolean;\n /**\n * Cerrar cuando la página hace scroll (fuera del panel). @default true\n * Con `false` el popover se reposiciona en vez de cerrarse — útil para un\n * dropdown de búsqueda que no debe desaparecer si enfocar el input provoca\n * un pequeño auto-scroll.\n */\n closeOnScroll?: boolean;\n /** Callback cuando se abre. */ \n onOpen?: () => void; \n /** Callback cuando se cierra. */ \n onClose?: () => void; \n} \n \nexport interface PopoverPosition {\n top: number;\n left: number;\n width?: number;\n maxHeight?: number;\n /** Placement final (puede diferir del solicitado si hubo flip). */\n placement: PopoverPlacement;\n} \n \n/**\n * Floor for the viewport cap. A trigger sitting a few pixels from the bottom\n * edge would otherwise get a panel too short to show anything; below this we\n * let the panel keep its own scroll instead.\n */\nconst MIN_PANEL_HEIGHT = 120;\n\n/**\n * Content height of a panel, independent of any `max-height` we have already\n * applied to it. `getBoundingClientRect()` reports the *constrained* height\n * once capped, so it can't be used to decide whether the panel still needs a\n * cap. The panel clips vertically and its inner wrapper is the scroll\n * container, so that wrapper's `scrollHeight` (plus the panel's own vertical\n * borders) is the height the panel would take if nothing constrained it.\n */\nfunction naturalHeight(panel: HTMLElement): number {\n const inner = panel.firstElementChild as HTMLElement | null;\n if (!inner) return panel.getBoundingClientRect().height;\n const styles = getComputedStyle(panel);\n const borders =\n Number.parseFloat(styles.borderTopWidth || '0')\n + Number.parseFloat(styles.borderBottomWidth || '0');\n return Math.max(inner.scrollHeight + borders, panel.getBoundingClientRect().height);\n}\n\n/**\n * Headless composable para lógica de popover/dropdown:\n * - estado abierto/cerrado \n * - click outside + Escape \n * - posición absoluta relativa al viewport (para usar con `position: fixed`) \n * - auto-flip vertical cuando no cabe \n * - reposicionado en scroll + resize + ResizeObserver del trigger \n * \n * El caller se encarga de renderizar el trigger y el panel; este composable \n * sólo devuelve refs y estado. \n */ \nexport function usePopover(options: UsePopoverOptions = {}) { \n const { \n placement: placementOption = 'bottom-start', \n offset = 6, \n flip = true, \n matchTriggerWidth: matchTriggerWidthOption = false, \n closeOnClickOutside = true,\n closeOnEscape = true,\n closeOnScroll = true,\n onOpen,\n onClose,\n } = options;\n \n const triggerRef = ref<HTMLElement | null>(null); \n const panelRef = ref<HTMLElement | null>(null); \n const isOpen = ref(false); \n \n const position = ref<PopoverPosition>({ \n top: 0, \n left: 0, \n placement: toValue(placementOption), \n }); \n \n const panelStyle = computed(() => {\n const style: Record<string, string> = {\n position: 'fixed',\n top: `${position.value.top}px`,\n left: `${position.value.left}px`,\n zIndex: '1300',\n };\n if (position.value.width !== undefined) {\n style.width = `${position.value.width}px`;\n }\n if (position.value.maxHeight !== undefined) {\n style.maxHeight = `${position.value.maxHeight}px`;\n }\n return style;\n }); \n \n function measure(): void {\n const trigger = triggerRef.value;\n const panel = panelRef.value;\n if (!trigger) return;\n\n const initialPlacement = toValue(placementOption);\n const matchTriggerWidth = toValue(matchTriggerWidthOption);\n\n const tRect = trigger.getBoundingClientRect();\n const pRect = panel?.getBoundingClientRect();\n const panelW = pRect?.width ?? tRect.width;\n // Height the panel *wants*, ignoring any cap we applied on a previous\n // pass. The panel clips its own overflow, so its scroll container holds\n // the real content height — without this, once we cap the panel its\n // measured height equals the cap and every later decision (flip, fit)\n // would be made against our own constraint instead of the content.\n const panelH = panel ? naturalHeight(panel) : 0;\n const vw = window.innerWidth;\n const vh = window.innerHeight;\n const margin = 8;\n\n let resolved: PopoverPlacement = initialPlacement; \n \n // Vertical flip check. \n if (flip) { \n const wantsTop = initialPlacement.startsWith('top'); \n const spaceBelow = vh - tRect.bottom - margin; \n const spaceAbove = tRect.top - margin; \n if (!wantsTop && spaceBelow < panelH && spaceAbove > spaceBelow) { \n resolved = initialPlacement.replace('bottom', 'top') as PopoverPlacement; \n } else if (wantsTop && spaceAbove < panelH && spaceBelow > spaceAbove) { \n resolved = initialPlacement.replace('top', 'bottom') as PopoverPlacement; \n } \n } \n \n const isBottom = resolved.startsWith('bottom');\n const align = resolved.split('-')[1] as 'start' | 'end' | 'center';\n\n // Vertical clamp: the panel may never grow past the edge of the\n // viewport, so cap it to whatever room the resolved side leaves. This\n // is applied unconditionally — capping only when the panel currently\n // overflows would make the cap oscillate: capped panel measures as\n // \"fits\", cap drops, content grows back past the edge, repeat.\n const availableH = isBottom\n ? vh - margin - (tRect.bottom + offset)\n : tRect.top - offset - margin;\n // A trigger scrolled past the edge of the viewport reports space that\n // does not exist on screen (`closeOnScroll: false` keeps the popover\n // open in exactly that state), so the room on the chosen side is not\n // enough on its own — the panel can never be taller than the viewport.\n const maxHeight = Math.max(\n Math.min(availableH, vh - margin * 2),\n MIN_PANEL_HEIGHT,\n );\n const renderedH = Math.min(panelH, maxHeight);\n\n let top = isBottom ? tRect.bottom + offset : tRect.top - renderedH - offset;\n\n let left: number; \n if (align === 'start') left = tRect.left; \n else if (align === 'end') left = tRect.right - panelW; \n else left = tRect.left + tRect.width / 2 - panelW / 2; \n \n // Horizontal clamp (simple, sin variante de flip lateral). \n if (left + panelW > vw - margin) left = vw - panelW - margin; \n if (left < margin) left = margin; \n \n if (top + renderedH > vh - margin) top = Math.max(margin, vh - renderedH - margin);\n if (top < margin) top = margin;\n\n position.value = {\n top,\n left,\n width: matchTriggerWidth ? tRect.width : undefined,\n maxHeight,\n placement: resolved,\n };\n }\n\n /* ---------- API ---------- */ \n \n function open() { \n if (isOpen.value) return; \n isOpen.value = true; \n onOpen?.(); \n // Medir en el próximo frame, cuando el panel ya esté en el DOM. \n requestAnimationFrame(() => { \n measure(); \n // Segunda pasada para corregir si aparecieron scrollbars. \n requestAnimationFrame(measure); \n }); \n } \n \n function close() { \n if (!isOpen.value) return; \n isOpen.value = false; \n onClose?.(); \n } \n \n function toggle() { \n isOpen.value ? close() : open(); \n } \n \n /* ---------- Listeners ---------- */ \n \n function onDocumentPointerDown(e: PointerEvent) { \n if (!isOpen.value || !closeOnClickOutside) return; \n const target = e.target as Element | null; \n if (!target) return; \n if (triggerRef.value?.contains(target)) return; \n if (panelRef.value?.contains(target)) return; \n // Click landed inside a *different* popover (e.g. a Select's \n // dropdown teleported to <body> from a child of our panel). \n // Treat any click on a `.modo-popover` ancestor as \"inside\" so \n // nested popovers don't close their parent. The parent will be \n // closed normally when the user clicks truly outside. \n if (typeof (target as Element).closest === 'function' && (target as Element).closest('.modo-popover')) { \n return; \n } \n close(); \n } \n \n function onDocumentKeyDown(e: KeyboardEvent) { \n if (!isOpen.value) return; \n if (closeOnEscape && e.key === 'Escape') { \n e.preventDefault(); \n close(); \n triggerRef.value?.focus?.(); \n } \n } \n \n function onScrollOrResize() { \n if (isOpen.value) measure(); \n } \n \n /** \n * Scroll outside del panel → cerrar. Scroll dentro del panel (p. ej. lista \n * de opciones) → no hace nada. Scroll en window/body → cerrar. \n * Se usa el evento \"scroll\" con capture para recibir cualquier scroll. \n */ \n function onWindowScroll(e: Event) {\n if (!isOpen.value) return;\n const target = e.target as Node | null;\n if (target && panelRef.value && panelRef.value.contains(target)) {\n // Scroll interno del panel — ignorar.\n return;\n }\n // Scroll inside a nested popover (Select's option list teleported\n // to <body>) should not close us either.\n if (target instanceof Element && target.closest('.modo-popover')) {\n return;\n }\n // Reposition instead of closing when the caller opted out of scroll-close.\n if (!closeOnScroll) { measure(); return; }\n close();\n }\n \n let resizeObserver: ResizeObserver | null = null;\n\n /**\n * Observe the panel *and* its scroll container. The panel itself stops\n * changing size once it hits the viewport cap, so growing content (async\n * search results, a longer list) would never notify us if we only watched\n * the outer box.\n */\n function observePanel(el: HTMLElement): void {\n resizeObserver?.observe(el);\n const inner = el.firstElementChild;\n if (inner instanceof HTMLElement) resizeObserver?.observe(inner);\n }\n\n watch(isOpen, (open) => { \n if (open) { \n document.addEventListener('pointerdown', onDocumentPointerDown, true); \n document.addEventListener('keydown', onDocumentKeyDown); \n // Scroll en cualquier contenedor (incluido window) cierra el popover \n // salvo si el scroll viene desde dentro del propio panel. \n window.addEventListener('scroll', onWindowScroll, true); \n window.addEventListener('resize', onScrollOrResize); \n if (triggerRef.value && typeof ResizeObserver !== 'undefined') { \n resizeObserver = new ResizeObserver(onScrollOrResize);\n resizeObserver.observe(triggerRef.value);\n if (panelRef.value) observePanel(panelRef.value);\n }\n } else { \n document.removeEventListener('pointerdown', onDocumentPointerDown, true); \n document.removeEventListener('keydown', onDocumentKeyDown); \n window.removeEventListener('scroll', onWindowScroll, true); \n window.removeEventListener('resize', onScrollOrResize); \n resizeObserver?.disconnect(); \n resizeObserver = null; \n } \n }); \n \n // Si el panel se monta después de open, vincularlo al ResizeObserver. \n watch(panelRef, (el) => {\n if (isOpen.value && el && resizeObserver) observePanel(el);\n });\n \n // Re-measure when reactive placement / matchTriggerWidth options change \n // while the popover is open (allows playgrounds to switch placement live). \n watch( \n () => [toValue(placementOption), toValue(matchTriggerWidthOption)], \n () => { if (isOpen.value) measure(); }, \n ); \n \n onBeforeUnmount(() => { \n document.removeEventListener('pointerdown', onDocumentPointerDown, true); \n document.removeEventListener('keydown', onDocumentKeyDown); \n window.removeEventListener('scroll', onWindowScroll, true); \n window.removeEventListener('resize', onScrollOrResize); \n resizeObserver?.disconnect(); \n }); \n \n return { \n triggerRef: triggerRef as Ref<HTMLElement | null>, \n panelRef: panelRef as Ref<HTMLElement | null>, \n isOpen, \n position, \n panelStyle, \n open, \n close, \n toggle, \n measure, \n }; \n}\n"],"mappings":";;;;;;;AA8CA,IAAM,mBAAmB;;;;;;;;;AAUzB,SAAS,cAAc,OAA4B;CAC/C,MAAM,QAAQ,MAAM;CACpB,IAAI,CAAC,OAAO,OAAO,MAAM,uBAAuB,CAAC;CACjD,MAAM,SAAS,iBAAiB,MAAM;CACtC,MAAM,UACF,OAAO,WAAW,OAAO,kBAAkB,IAAI,GAC7C,OAAO,WAAW,OAAO,qBAAqB,IAAI;CACxD,OAAO,KAAK,IAAI,MAAM,eAAe,SAAS,MAAM,uBAAuB,CAAC,OAAO;;;;;;;;;;;;;AAc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AK;GACxE,SAAS,oBAAoB,WAAW,kBAAkB;GAC1D,OAAO,oBAAoB,UAAU,gBAAgB,KAAK;GAC1D,OAAO,oBAAoB,UAAU,iBAAiB;GACtD,gBAAgB,YAAY;GAC5B,iBAAiB;;GAEvB;CAGF,MAAM,WAAW,OAAO;EACpB,IAAI,OAAO,SAAS,MAAM,gBAAgB,aAAa,GAAG;GAC5D;CAIF,YACU,CAAC,QAAQ,gBAAgB,EAAE,QAAQ,wBAAwB,CAAC,QAC5D;EAAE,IAAI,OAAO,OAAO,SAAS;GACtC;CAED,sBAAsB;EAClB,SAAS,oBAAoB,eAAe,uBAAuB,KAAK;EACxE,SAAS,oBAAoB,WAAW,kBAAkB;EAC1D,OAAO,oBAAoB,UAAU,gBAAgB,KAAK;EAC1D,OAAO,oBAAoB,UAAU,iBAAiB;EACtD,gBAAgB,YAAY;GAC9B;CAEF,OAAO;EACS;EACF;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACH"}
|
package/dist/mood-ui.css
CHANGED
|
@@ -109,30 +109,30 @@ button[data-v-15141189],
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
.modo-popover[data-v-
|
|
112
|
+
.modo-popover[data-v-8bb79aba] {
|
|
113
113
|
transform-origin: top center;
|
|
114
114
|
will-change: transform, opacity;
|
|
115
115
|
}
|
|
116
|
-
.modo-popover-enter[data-v-
|
|
117
|
-
animation: modo-popover-in-
|
|
116
|
+
.modo-popover-enter[data-v-8bb79aba] {
|
|
117
|
+
animation: modo-popover-in-8bb79aba 140ms cubic-bezier(0.2, 0, 0, 1);
|
|
118
118
|
}
|
|
119
|
-
.modo-popover-leave[data-v-
|
|
120
|
-
animation: modo-popover-out-
|
|
119
|
+
.modo-popover-leave[data-v-8bb79aba] {
|
|
120
|
+
animation: modo-popover-out-8bb79aba 80ms cubic-bezier(0.3, 0, 1, 1);
|
|
121
121
|
}
|
|
122
|
-
@keyframes modo-popover-in-
|
|
122
|
+
@keyframes modo-popover-in-8bb79aba {
|
|
123
123
|
from { opacity: 0; transform: translateY(-4px) scale(0.98);
|
|
124
124
|
}
|
|
125
125
|
to { opacity: 1; transform: translateY(0) scale(1);
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
|
-
@keyframes modo-popover-out-
|
|
128
|
+
@keyframes modo-popover-out-8bb79aba {
|
|
129
129
|
from { opacity: 1; transform: translateY(0);
|
|
130
130
|
}
|
|
131
131
|
to { opacity: 0; transform: translateY(-2px);
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
134
|
@media (prefers-reduced-motion: reduce) {
|
|
135
|
-
.modo-popover-enter[data-v-
|
|
135
|
+
.modo-popover-enter[data-v-8bb79aba], .modo-popover-leave[data-v-8bb79aba] { animation: none;
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
|
|
@@ -151,7 +151,7 @@ to { opacity: 0; transform: translateY(-2px);
|
|
|
151
151
|
background-color: var(--color-muted);
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
.month-disabled-day[data-v-
|
|
154
|
+
.month-disabled-day[data-v-2305fe25] {
|
|
155
155
|
background-image: repeating-linear-gradient(135deg, transparent 0 6px, rgba(0, 0, 0, 0.04) 6px 7px);
|
|
156
156
|
}
|
|
157
157
|
|
|
@@ -4,10 +4,10 @@ export type EventColor = 'default' | 'primary' | 'danger' | 'success' | 'warning
|
|
|
4
4
|
* Translucent fills (`/15`) so the underlying grid lines stay visible —
|
|
5
5
|
* matches the look of `colorHex` events that use `rgba(..., 0.12)`.
|
|
6
6
|
*/
|
|
7
|
-
export declare const eventColorClass: (c?: EventColor | null) => string;
|
|
7
|
+
export declare const eventColorClass: (c?: EventColor | null, accent?: boolean) => string;
|
|
8
8
|
/**
|
|
9
9
|
* Stronger variant used in MonthView (pill-like events) — slightly more
|
|
10
10
|
* opaque to stay readable in compact pills.
|
|
11
11
|
*/
|
|
12
|
-
export declare const eventColorClassStrong: (c?: EventColor | null) => string;
|
|
12
|
+
export declare const eventColorClassStrong: (c?: EventColor | null, accent?: boolean) => string;
|
|
13
13
|
export declare const hexToRgba: (hex: string, alpha: number) => string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reference-counted `<body>` scroll lock, shared by every overlay that needs
|
|
3
|
+
* one (Modal, Drawer, …).
|
|
4
|
+
*
|
|
5
|
+
* Each overlay used to save and restore `body.style.overflow` on its own. That
|
|
6
|
+
* breaks as soon as two overlays are open at once: the second one saves the
|
|
7
|
+
* *locked* value (`'hidden'`) as the thing to restore, so whichever releases
|
|
8
|
+
* last writes `overflow: hidden` back onto <body> and the page can never
|
|
9
|
+
* scroll again. Counting holders here means the original values are captured
|
|
10
|
+
* once, by the first lock, and restored once, by the last release.
|
|
11
|
+
*
|
|
12
|
+
* Callers must pair every `lockBodyScroll()` with exactly one
|
|
13
|
+
* `unlockBodyScroll()` — components track that with an instance-level flag so
|
|
14
|
+
* a double release cannot drop the count below zero.
|
|
15
|
+
*/
|
|
16
|
+
export declare function lockBodyScroll(): void;
|
|
17
|
+
export declare function unlockBodyScroll(): void;
|
|
18
|
+
/** Test-only escape hatch so specs can start from a known state. */
|
|
19
|
+
export declare function __resetBodyScrollLock(): void;
|
|
@@ -15,6 +15,8 @@ export interface CalendarTheme {
|
|
|
15
15
|
highlightDotClass: ComputedRef<string>;
|
|
16
16
|
containerRadiusClass: ComputedRef<string>;
|
|
17
17
|
eventRadiusClass: ComputedRef<string>;
|
|
18
|
+
/** Whether an event's left colour rule reads as a bar at the current radius. */
|
|
19
|
+
showEventAccent: ComputedRef<boolean>;
|
|
18
20
|
pillRadiusClass: ComputedRef<string>;
|
|
19
21
|
dayNameCaseClass: ComputedRef<string>;
|
|
20
22
|
resolvedColor: ComputedRef<CalendarColor>;
|
|
@@ -6,6 +6,11 @@ export interface AgendaView {
|
|
|
6
6
|
color?: 'default' | 'primary' | 'danger' | 'success' | 'warning';
|
|
7
7
|
radius?: 'none' | 'small' | 'medium' | 'large' | 'full';
|
|
8
8
|
bordered?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Caps the view's height so its body scrolls internally instead of growing
|
|
11
|
+
* with the content. Bare numbers are pixels; strings take any CSS unit.
|
|
12
|
+
*/
|
|
13
|
+
maxHeight?: number | string;
|
|
9
14
|
minDate?: Date;
|
|
10
15
|
maxDate?: Date;
|
|
11
16
|
daysToShow?: number;
|
|
@@ -7,6 +7,11 @@ export interface DayView {
|
|
|
7
7
|
color?: 'default' | 'primary' | 'danger' | 'success' | 'warning';
|
|
8
8
|
radius?: 'none' | 'small' | 'medium' | 'large' | 'full';
|
|
9
9
|
bordered?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Caps the view's height so its body scrolls internally instead of growing
|
|
12
|
+
* with the content. Bare numbers are pixels; strings take any CSS unit.
|
|
13
|
+
*/
|
|
14
|
+
maxHeight?: number | string;
|
|
10
15
|
minDate?: Date;
|
|
11
16
|
maxDate?: Date;
|
|
12
17
|
dayNameFormat?: 'narrow' | 'short' | 'long';
|
|
@@ -23,6 +23,11 @@ export interface MonthView {
|
|
|
23
23
|
fixedWeeks?: boolean;
|
|
24
24
|
showHeader?: boolean;
|
|
25
25
|
bordered?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Caps the view's height so its body scrolls internally instead of growing
|
|
28
|
+
* with the content. Bare numbers are pixels; strings take any CSS unit.
|
|
29
|
+
*/
|
|
30
|
+
maxHeight?: number | string;
|
|
26
31
|
keyboardNavigation?: boolean;
|
|
27
32
|
minDate?: Date;
|
|
28
33
|
maxDate?: Date;
|
|
@@ -22,6 +22,11 @@ export interface Scheduler {
|
|
|
22
22
|
color?: 'default' | 'primary' | 'danger' | 'success' | 'warning';
|
|
23
23
|
radius?: 'none' | 'small' | 'medium' | 'large' | 'full';
|
|
24
24
|
bordered?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Caps the view's height so its body scrolls internally instead of growing
|
|
27
|
+
* with the content. Bare numbers are pixels; strings take any CSS unit.
|
|
28
|
+
*/
|
|
29
|
+
maxHeight?: number | string;
|
|
25
30
|
minDate?: Date;
|
|
26
31
|
maxDate?: Date;
|
|
27
32
|
dayNameFormat?: 'narrow' | 'short' | 'long';
|
|
@@ -17,6 +17,11 @@ export interface WeekView {
|
|
|
17
17
|
color?: 'default' | 'primary' | 'danger' | 'success' | 'warning';
|
|
18
18
|
radius?: 'none' | 'small' | 'medium' | 'large' | 'full';
|
|
19
19
|
bordered?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Caps the view's height so its body scrolls internally instead of growing
|
|
22
|
+
* with the content. Bare numbers are pixels; strings take any CSS unit.
|
|
23
|
+
*/
|
|
24
|
+
maxHeight?: number | string;
|
|
20
25
|
minDate?: Date;
|
|
21
26
|
maxDate?: Date;
|
|
22
27
|
dayNameFormat?: 'narrow' | 'short' | 'long';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Geometry for the tooltip arrow — a square rotated 45° that straddles one edge
|
|
3
|
+
* of the panel, so only the outward-facing corner shows past it.
|
|
4
|
+
*
|
|
5
|
+
* Two things make the arrow read as a diamond instead of a tip:
|
|
6
|
+
*
|
|
7
|
+
* 1. Its rotated silhouette is wider than its box. An 8px square spans
|
|
8
|
+
* 8 * √2 ≈ 11.3px once rotated, so it needs half of that — plus the panel's
|
|
9
|
+
* corner radius — of clearance from either end of the edge. Park it closer
|
|
10
|
+
* and a side corner pokes out past the rounded corner, outside the panel's
|
|
11
|
+
* silhouette.
|
|
12
|
+
* 2. The cross-axis value points at the *centre* of the trigger, so it has to
|
|
13
|
+
* be applied as a centre, not as the box's leading edge. Using it raw as
|
|
14
|
+
* `left`/`top` shifts the arrow by half its size — invisible on a wide
|
|
15
|
+
* tooltip, decisive on a narrow one.
|
|
16
|
+
*/
|
|
17
|
+
/** Side of the (unrotated) arrow square, in px. Must match the `w-2 h-2` class. */
|
|
18
|
+
export declare const TOOLTIP_ARROW_SIZE = 8;
|
|
19
|
+
/**
|
|
20
|
+
* Minimum distance from either end of the panel edge at which the arrow's
|
|
21
|
+
* centre may sit. `full` has no straight edge to sit on, so it reports an inset
|
|
22
|
+
* large enough to force the centred fallback below.
|
|
23
|
+
*/
|
|
24
|
+
export declare function tooltipArrowInset(radius: string, panelSize: number): number;
|
|
25
|
+
/**
|
|
26
|
+
* Centre of the arrow along the panel edge, in panel-local px.
|
|
27
|
+
*
|
|
28
|
+
* `triggerCentre` is where the arrow would ideally point. A panel too small to
|
|
29
|
+
* hold the arrow anywhere clear of both corners gets it centred instead — that
|
|
30
|
+
* is the small-tooltip case, where clamping to `[inset, panelSize - inset]`
|
|
31
|
+
* inverts (the upper bound falls below the lower one) and pushed the arrow off
|
|
32
|
+
* the wrong end of the panel.
|
|
33
|
+
*/
|
|
34
|
+
export declare function tooltipArrowCross(triggerCentre: number, panelSize: number, inset: number): number;
|