material-plus-ui 1.7.0 → 1.8.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/LICENSE +1 -1
- package/README.md +20 -14
- package/dist/components/alert/MPAlert.d.ts +1 -1
- package/dist/components/alert/MPAlert.js +1 -1
- package/dist/components/anchor/MPAnchor.js +1 -1
- package/dist/components/animate-counter/MPAnimateCounter.js +1 -1
- package/dist/components/app-logo/MPAppLogo.d.ts +16 -1
- package/dist/components/app-logo/MPAppLogo.js +1 -1
- package/dist/components/aspect-ratio/MPAspectRatio.d.ts +1 -1
- package/dist/components/aspect-ratio/MPAspectRatio.js +1 -1
- package/dist/components/blockquote/MPBlockquote.d.ts +8 -0
- package/dist/components/blockquote/MPBlockquote.js +1 -1
- package/dist/components/bottom-navigation/MPBottomNavigation.js +1 -1
- package/dist/components/breadcrumb/MPBreadcrumb.js +1 -1
- package/dist/components/button/MPButton.js +1 -1
- package/dist/components/calendar/MPCalendar.js +1 -1
- package/dist/components/carousel/MPCarousel.js +1 -1
- package/dist/components/checkbox/MPCheckbox.js +1 -1
- package/dist/components/chip/MPChip.d.ts +1 -1
- package/dist/components/chip/MPChip.js +1 -1
- package/dist/components/color-picker/MPColorPicker.js +1 -1
- package/dist/components/combobox/MPCombobox.js +1 -1
- package/dist/components/confirm/MPConfirmProvider.js +1 -1
- package/dist/components/data-table/MPDataTable.d.ts +20 -1
- package/dist/components/data-table/MPDataTable.js +1 -1
- package/dist/components/date-picker/MPDatePicker.js +1 -1
- package/dist/components/floating-action-button/MPFloatingActionButton.js +1 -1
- package/dist/components/grid/MPGrid.d.ts +25 -8
- package/dist/components/grid/MPGrid.js +1 -1
- package/dist/components/hover-card/MPHoverCard.d.ts +1 -0
- package/dist/components/hover-card/MPHoverCard.js +1 -1
- package/dist/components/icon/MPIcon.js +1 -1
- package/dist/components/image/MPImage.d.ts +112 -4
- package/dist/components/image/MPImage.js +1 -1
- package/dist/components/image/index.d.ts +1 -1
- package/dist/components/list/MPList.js +1 -1
- package/dist/components/menu/MPMenu.d.ts +1 -1
- package/dist/components/menubar/MPMenubar.js +1 -1
- package/dist/components/navigation-menu/MPNavigationMenu.js +1 -1
- package/dist/components/number-field/MPNumberField.js +1 -1
- package/dist/components/pie-chart/MPPieChart.js +1 -1
- package/dist/components/pill/MPPill.js +1 -1
- package/dist/components/popconfirm/MPPopconfirm.d.ts +2 -2
- package/dist/components/popover/MPPopover.d.ts +1 -0
- package/dist/components/popover/MPPopover.js +1 -1
- package/dist/components/portal/MPPortal.d.ts +1 -1
- package/dist/components/radio-group/MPRadioGroup.js +1 -1
- package/dist/components/rating/MPRating.js +1 -1
- package/dist/components/segmented-button/MPSegmentedButton.js +1 -1
- package/dist/components/select/MPSelect.js +1 -1
- package/dist/components/sparkline/MPSparkline.js +1 -1
- package/dist/components/statistic/MPStatistic.js +1 -1
- package/dist/components/stepper/MPStepper.js +1 -1
- package/dist/components/table/MPTable.d.ts +1 -1
- package/dist/components/tabs/MPTabs.js +1 -1
- package/dist/components/timeline/MPTimeline.js +1 -1
- package/dist/components/toggle/MPToggle.js +1 -1
- package/dist/components/tooltip/MPTooltip.js +1 -1
- package/dist/components/tour/MPTour.js +1 -1
- package/dist/components/transfer/MPTransfer.js +1 -1
- package/dist/constants/glyphs.d.ts +32 -32
- package/dist/constants/icons.d.ts +32 -32
- package/dist/internal/Calendar.js +1 -1
- package/dist/internal/ChartChrome.d.ts +0 -6
- package/dist/internal/ChartChrome.js +1 -1
- package/dist/internal/FieldOutline.js +1 -1
- package/dist/internal/Picker.js +1 -1
- package/dist/internal/PopupArrow.d.ts +60 -0
- package/dist/internal/PopupArrow.js +2 -0
- package/dist/internal/SupportingText.js +1 -1
- package/dist/internal/chart.d.ts +0 -10
- package/dist/internal/chart.js +1 -1
- package/dist/internal/color-scheme.d.ts +0 -9
- package/dist/internal/color-scheme.js +1 -1
- package/dist/internal/data-table.d.ts +35 -2
- package/dist/internal/data-table.js +1 -1
- package/dist/internal/date.d.ts +22 -18
- package/dist/internal/date.js +1 -1
- package/dist/internal/i18n.d.ts +10 -0
- package/dist/internal/intl.d.ts +64 -0
- package/dist/internal/intl.js +1 -0
- package/dist/internal/messages/transfer.d.ts +1 -1
- package/dist/internal/messages/transfer.js +1 -1
- package/dist/internal/text.js +1 -1
- package/dist/internal/time-scale.js +1 -1
- package/dist/locales/ar.js +1 -1
- package/dist/locales/de.js +1 -1
- package/dist/locales/es.js +1 -1
- package/dist/locales/fr.js +1 -1
- package/dist/locales/hi.js +1 -1
- package/dist/locales/id.js +1 -1
- package/dist/locales/it.js +1 -1
- package/dist/locales/ja.js +1 -1
- package/dist/locales/ko.js +1 -1
- package/dist/locales/nl.js +1 -1
- package/dist/locales/pl.js +1 -1
- package/dist/locales/pt.js +1 -1
- package/dist/locales/ru.js +1 -1
- package/dist/locales/th.js +1 -1
- package/dist/locales/tr.js +1 -1
- package/dist/locales/vi.js +1 -1
- package/dist/locales/zh-hans.js +1 -1
- package/dist/locales/zh-hant.js +1 -1
- package/dist/styles/accordion.css +1 -1
- package/dist/styles/alert.css +1 -1
- package/dist/styles/app-logo.css +1 -1
- package/dist/styles/area-chart.css +1 -1
- package/dist/styles/aspect-ratio.css +1 -1
- package/dist/styles/bar-chart.css +1 -1
- package/dist/styles/blockquote.css +1 -1
- package/dist/styles/bottom-navigation.css +1 -1
- package/dist/styles/breadcrumb.css +1 -1
- package/dist/styles/button.css +1 -1
- package/dist/styles/calendar.css +1 -1
- package/dist/styles/carousel.css +1 -1
- package/dist/styles/chat-bubble.css +1 -1
- package/dist/styles/checkbox.css +1 -1
- package/dist/styles/chip.css +1 -1
- package/dist/styles/code-block.css +1 -1
- package/dist/styles/collapsible.css +1 -1
- package/dist/styles/color-picker.css +1 -1
- package/dist/styles/combobox.css +1 -1
- package/dist/styles/confirm.css +1 -1
- package/dist/styles/data-table.css +1 -1
- package/dist/styles/date-picker.css +1 -1
- package/dist/styles/date-range-picker.css +1 -1
- package/dist/styles/date-time-picker.css +1 -1
- package/dist/styles/dialog.css +1 -1
- package/dist/styles/drawer.css +1 -1
- package/dist/styles/file-picker.css +1 -1
- package/dist/styles/flex.css +1 -1
- package/dist/styles/floating-action-button.css +1 -1
- package/dist/styles/grid.css +1 -1
- package/dist/styles/heatmap-chart.css +1 -1
- package/dist/styles/icon-button.css +1 -1
- package/dist/styles/icon.css +1 -1
- package/dist/styles/image.css +1 -1
- package/dist/styles/line-chart.css +1 -1
- package/dist/styles/list.css +1 -1
- package/dist/styles/menu.css +1 -1
- package/dist/styles/menubar.css +1 -1
- package/dist/styles/navigation-menu.css +1 -1
- package/dist/styles/number-field.css +1 -1
- package/dist/styles/otp-field.css +1 -1
- package/dist/styles/pagination.css +1 -1
- package/dist/styles/pie-chart.css +1 -1
- package/dist/styles/pill.css +1 -1
- package/dist/styles/popconfirm.css +1 -1
- package/dist/styles/popover.css +1 -1
- package/dist/styles/radio-group.css +1 -1
- package/dist/styles/rating.css +1 -1
- package/dist/styles/scatter-chart.css +1 -1
- package/dist/styles/scroll-zone.css +1 -1
- package/dist/styles/segmented-button.css +1 -1
- package/dist/styles/select.css +1 -1
- package/dist/styles/sidebar.css +1 -1
- package/dist/styles/snackbar.css +1 -1
- package/dist/styles/spoiler.css +1 -1
- package/dist/styles/statistic.css +1 -1
- package/dist/styles/stepper.css +1 -1
- package/dist/styles/switch.css +1 -1
- package/dist/styles/tabs.css +1 -1
- package/dist/styles/text-field.css +1 -1
- package/dist/styles/text-link.css +1 -1
- package/dist/styles/time-picker.css +1 -1
- package/dist/styles/timeline-chart.css +1 -1
- package/dist/styles/timeline.css +1 -1
- package/dist/styles/toggle.css +1 -1
- package/dist/styles/tokens.css +1 -1
- package/dist/styles/tour.css +1 -1
- package/dist/styles/transfer.css +1 -1
- package/dist/styles/tree-select.css +1 -1
- package/dist/styles/tree-view.css +1 -1
- package/dist/styles.css +1 -1
- package/dist/tailwind.css +1253 -55
- package/dist/types.d.ts +2 -2
- package/package.json +24 -24
- package/.fix.py +0 -92
|
@@ -1,69 +1,69 @@
|
|
|
1
1
|
/** The glyph a password field shows while the password is legible. */
|
|
2
|
-
export declare const VisibilityIcon: import("
|
|
2
|
+
export declare const VisibilityIcon: import("lucide-react").LucideIcon;
|
|
3
3
|
/** The glyph a password field shows while the password is masked. */
|
|
4
|
-
export declare const VisibilityOffIcon: import("
|
|
4
|
+
export declare const VisibilityOffIcon: import("lucide-react").LucideIcon;
|
|
5
5
|
/** Dismiss: a chip, a dialog, an alert. */
|
|
6
|
-
export declare const CloseIcon: import("
|
|
6
|
+
export declare const CloseIcon: import("lucide-react").LucideIcon;
|
|
7
7
|
/** A ticked option, a completed step. */
|
|
8
|
-
export declare const CheckIcon: import("
|
|
8
|
+
export declare const CheckIcon: import("lucide-react").LucideIcon;
|
|
9
9
|
/** Disclosure, pointing down. */
|
|
10
|
-
export declare const ChevronDownIcon: import("
|
|
10
|
+
export declare const ChevronDownIcon: import("lucide-react").LucideIcon;
|
|
11
11
|
/** Disclosure, pointing up. */
|
|
12
|
-
export declare const ChevronUpIcon: import("
|
|
12
|
+
export declare const ChevronUpIcon: import("lucide-react").LucideIcon;
|
|
13
13
|
/** Previous, in a pager or a carousel. */
|
|
14
|
-
export declare const ChevronLeftIcon: import("
|
|
14
|
+
export declare const ChevronLeftIcon: import("lucide-react").LucideIcon;
|
|
15
15
|
/** Next, in a pager or a carousel. */
|
|
16
|
-
export declare const ChevronRightIcon: import("
|
|
16
|
+
export declare const ChevronRightIcon: import("lucide-react").LucideIcon;
|
|
17
17
|
/** First, in a pager: the stepper that jumps to an end rather than by one. */
|
|
18
|
-
export declare const ChevronsLeftIcon: import("
|
|
18
|
+
export declare const ChevronsLeftIcon: import("lucide-react").LucideIcon;
|
|
19
19
|
/** And last. */
|
|
20
|
-
export declare const ChevronsRightIcon: import("
|
|
20
|
+
export declare const ChevronsRightIcon: import("lucide-react").LucideIcon;
|
|
21
21
|
/** Search, for a field's leading adornment. */
|
|
22
|
-
export declare const SearchIcon: import("
|
|
22
|
+
export declare const SearchIcon: import("lucide-react").LucideIcon;
|
|
23
23
|
/** Sorted ascending: the arrow a table's sorted column carries. */
|
|
24
|
-
export declare const ArrowUpIcon: import("
|
|
24
|
+
export declare const ArrowUpIcon: import("lucide-react").LucideIcon;
|
|
25
25
|
/** Sorted descending. */
|
|
26
|
-
export declare const ArrowDownIcon: import("
|
|
26
|
+
export declare const ArrowDownIcon: import("lucide-react").LucideIcon;
|
|
27
27
|
/** And then: the mark a breadcrumb can put between two steps. */
|
|
28
|
-
export declare const ArrowRightIcon: import("
|
|
28
|
+
export declare const ArrowRightIcon: import("lucide-react").LucideIcon;
|
|
29
29
|
/** The trail a breadcrumb hides behind, and any other "there is more here". */
|
|
30
|
-
export declare const MoreIcon: import("
|
|
30
|
+
export declare const MoreIcon: import("lucide-react").LucideIcon;
|
|
31
31
|
/** A link that goes somewhere on this site. */
|
|
32
|
-
export declare const LinkIcon: import("
|
|
32
|
+
export declare const LinkIcon: import("lucide-react").LucideIcon;
|
|
33
33
|
/** A link that takes over the window. */
|
|
34
|
-
export declare const ExternalLinkIcon: import("
|
|
34
|
+
export declare const ExternalLinkIcon: import("lucide-react").LucideIcon;
|
|
35
35
|
/** Copy to clipboard. */
|
|
36
|
-
export declare const CopyIcon: import("
|
|
36
|
+
export declare const CopyIcon: import("lucide-react").LucideIcon;
|
|
37
37
|
/** Source as it was written — `MPCodeBlock`'s toggle out of the colouring. */
|
|
38
|
-
export declare const CodeIcon: import("
|
|
38
|
+
export declare const CodeIcon: import("lucide-react").LucideIcon;
|
|
39
39
|
/** A picture that could not be fetched — `MPImage`'s own fallback. */
|
|
40
|
-
export declare const BrokenImageIcon: import("
|
|
40
|
+
export declare const BrokenImageIcon: import("lucide-react").LucideIcon;
|
|
41
41
|
/** Severity: something worth knowing. */
|
|
42
|
-
export declare const InfoIcon: import("
|
|
42
|
+
export declare const InfoIcon: import("lucide-react").LucideIcon;
|
|
43
43
|
/** Severity: it worked. */
|
|
44
|
-
export declare const SuccessIcon: import("
|
|
44
|
+
export declare const SuccessIcon: import("lucide-react").LucideIcon;
|
|
45
45
|
/** Severity: proceed carefully. */
|
|
46
|
-
export declare const WarningIcon: import("
|
|
46
|
+
export declare const WarningIcon: import("lucide-react").LucideIcon;
|
|
47
47
|
/** Severity: it did not work. */
|
|
48
|
-
export declare const ErrorIcon: import("
|
|
48
|
+
export declare const ErrorIcon: import("lucide-react").LucideIcon;
|
|
49
49
|
/** One step up: a number field's increment. */
|
|
50
|
-
export declare const AddIcon: import("
|
|
50
|
+
export declare const AddIcon: import("lucide-react").LucideIcon;
|
|
51
51
|
/** One step down: a number field's decrement, and a half-ticked checkbox. */
|
|
52
|
-
export declare const RemoveIcon: import("
|
|
52
|
+
export declare const RemoveIcon: import("lucide-react").LucideIcon;
|
|
53
53
|
/** Send a file the other way. A file picker's dropzone. */
|
|
54
|
-
export declare const UploadIcon: import("
|
|
54
|
+
export declare const UploadIcon: import("lucide-react").LucideIcon;
|
|
55
55
|
/** A day on a calendar: what a date picker's trigger wears. */
|
|
56
|
-
export declare const CalendarIcon: import("
|
|
56
|
+
export declare const CalendarIcon: import("lucide-react").LucideIcon;
|
|
57
57
|
/** A time of day: what a time picker's trigger wears. */
|
|
58
|
-
export declare const ClockIcon: import("
|
|
58
|
+
export declare const ClockIcon: import("lucide-react").LucideIcon;
|
|
59
59
|
/**
|
|
60
60
|
* A score. Drawn as an outline, and filled by whatever is scoring with it —
|
|
61
61
|
* lucide draws it `fill="none"`, and `MPRating` overlays a copy in `fill-current`
|
|
62
62
|
* rather than shipping a second glyph.
|
|
63
63
|
*/
|
|
64
|
-
export declare const StarIcon: import("
|
|
64
|
+
export declare const StarIcon: import("lucide-react").LucideIcon;
|
|
65
65
|
/** Work in progress, spun by whatever is waiting on it. */
|
|
66
|
-
export declare const SpinnerIcon: import("
|
|
66
|
+
export declare const SpinnerIcon: import("lucide-react").LucideIcon;
|
|
67
67
|
/**
|
|
68
68
|
* Three lines: the navigation a window has become too narrow to show.
|
|
69
69
|
*
|
|
@@ -73,4 +73,4 @@ export declare const SpinnerIcon: import("react").ForwardRefExoticComponent<Omit
|
|
|
73
73
|
* argument that ever justifies a symbol — and `MPSidebarTrigger` gives it a
|
|
74
74
|
* name for the readers it still says nothing to.
|
|
75
75
|
*/
|
|
76
|
-
export declare const MenuIcon: import("
|
|
76
|
+
export declare const MenuIcon: import("lucide-react").LucideIcon;
|
|
@@ -41,38 +41,38 @@ export * from './glyphs.js';
|
|
|
41
41
|
* file. Reach for the named exports when only one or two are needed.
|
|
42
42
|
*/
|
|
43
43
|
export declare const ICONS: {
|
|
44
|
-
readonly visibility: import("
|
|
45
|
-
readonly 'visibility-off': import("
|
|
46
|
-
readonly close: import("
|
|
47
|
-
readonly check: import("
|
|
48
|
-
readonly 'chevron-down': import("
|
|
49
|
-
readonly 'chevron-up': import("
|
|
50
|
-
readonly 'chevron-left': import("
|
|
51
|
-
readonly 'chevron-right': import("
|
|
52
|
-
readonly 'chevrons-left': import("
|
|
53
|
-
readonly 'chevrons-right': import("
|
|
54
|
-
readonly search: import("
|
|
55
|
-
readonly 'arrow-up': import("
|
|
56
|
-
readonly 'arrow-down': import("
|
|
57
|
-
readonly 'arrow-right': import("
|
|
58
|
-
readonly more: import("
|
|
59
|
-
readonly menu: import("
|
|
60
|
-
readonly link: import("
|
|
61
|
-
readonly 'external-link': import("
|
|
62
|
-
readonly copy: import("
|
|
63
|
-
readonly code: import("
|
|
64
|
-
readonly 'broken-image': import("
|
|
65
|
-
readonly info: import("
|
|
66
|
-
readonly success: import("
|
|
67
|
-
readonly warning: import("
|
|
68
|
-
readonly error: import("
|
|
69
|
-
readonly add: import("
|
|
70
|
-
readonly remove: import("
|
|
71
|
-
readonly upload: import("
|
|
72
|
-
readonly calendar: import("
|
|
73
|
-
readonly clock: import("
|
|
74
|
-
readonly star: import("
|
|
75
|
-
readonly spinner: import("
|
|
44
|
+
readonly visibility: import("lucide-react").LucideIcon;
|
|
45
|
+
readonly 'visibility-off': import("lucide-react").LucideIcon;
|
|
46
|
+
readonly close: import("lucide-react").LucideIcon;
|
|
47
|
+
readonly check: import("lucide-react").LucideIcon;
|
|
48
|
+
readonly 'chevron-down': import("lucide-react").LucideIcon;
|
|
49
|
+
readonly 'chevron-up': import("lucide-react").LucideIcon;
|
|
50
|
+
readonly 'chevron-left': import("lucide-react").LucideIcon;
|
|
51
|
+
readonly 'chevron-right': import("lucide-react").LucideIcon;
|
|
52
|
+
readonly 'chevrons-left': import("lucide-react").LucideIcon;
|
|
53
|
+
readonly 'chevrons-right': import("lucide-react").LucideIcon;
|
|
54
|
+
readonly search: import("lucide-react").LucideIcon;
|
|
55
|
+
readonly 'arrow-up': import("lucide-react").LucideIcon;
|
|
56
|
+
readonly 'arrow-down': import("lucide-react").LucideIcon;
|
|
57
|
+
readonly 'arrow-right': import("lucide-react").LucideIcon;
|
|
58
|
+
readonly more: import("lucide-react").LucideIcon;
|
|
59
|
+
readonly menu: import("lucide-react").LucideIcon;
|
|
60
|
+
readonly link: import("lucide-react").LucideIcon;
|
|
61
|
+
readonly 'external-link': import("lucide-react").LucideIcon;
|
|
62
|
+
readonly copy: import("lucide-react").LucideIcon;
|
|
63
|
+
readonly code: import("lucide-react").LucideIcon;
|
|
64
|
+
readonly 'broken-image': import("lucide-react").LucideIcon;
|
|
65
|
+
readonly info: import("lucide-react").LucideIcon;
|
|
66
|
+
readonly success: import("lucide-react").LucideIcon;
|
|
67
|
+
readonly warning: import("lucide-react").LucideIcon;
|
|
68
|
+
readonly error: import("lucide-react").LucideIcon;
|
|
69
|
+
readonly add: import("lucide-react").LucideIcon;
|
|
70
|
+
readonly remove: import("lucide-react").LucideIcon;
|
|
71
|
+
readonly upload: import("lucide-react").LucideIcon;
|
|
72
|
+
readonly calendar: import("lucide-react").LucideIcon;
|
|
73
|
+
readonly clock: import("lucide-react").LucideIcon;
|
|
74
|
+
readonly star: import("lucide-react").LucideIcon;
|
|
75
|
+
readonly spinner: import("lucide-react").LucideIcon;
|
|
76
76
|
};
|
|
77
77
|
/** Every role name `ICONS` answers to. */
|
|
78
78
|
export type MPIconName = keyof typeof ICONS;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import*as o from"react";import{MPButton as r}from"../components/button/MPButton.js";import{MPIcon as l}from"../components/icon/MPIcon.js";import{MPIconButton as a}from"../components/icon-button/MPIconButton.js";import{ChevronDownIcon as s,ChevronLeftIcon as c,ChevronRightIcon as i}from"../constants/icons.js";import{MPStateLayer as u}from"./StateLayer.js";import{CONTROL_ICON as m,META_TEXT as d,PROSE_TEXT as h}from"./scale.js";import{VISUALLY_HIDDEN as p}from"./visually-hidden.js";import{addDays as f,addMonths as g,addYears as y,calendarWeeks as v,compareDay as b,dateFormatter as w,isDayOutside as x,isMonthBeforeYear as D,isSameDay as S,isSameMonth as M,isUnitOutside as N,isValidDate as P,makeDate as _,meridiemLabels as C,monthLabels as k,startOfDay as j,startOfMonth as z,today as A,weekdayLabels as E,withTime as T,YEAR_PAGE_SIZE as F,yearPageStart as Y}from"./date.js";const B={xs:"1.75rem",sm:"2rem",md:"2.5rem",lg:"2.75rem",xl:"3rem"},R={xs:"xs",sm:"xs",md:"sm",lg:"sm",xl:"md"},H=/*@__PURE__*/["group relative flex cursor-pointer items-center justify-center overflow-hidden","box-border appearance-none font-[inherit] tabular-nums select-none","transition-[background-color,border-color,color]","duration-(--mp-sys-motion-duration-short4)","outline-mp-secondary focus-visible:z-10 focus-visible:outline-2","focus-visible:outline-offset-[-2px] focus-visible:outline-solid outline-none"].join(" "),$={day:0,month:1,year:2};function K({children:n,label:o,selected:r,inRange:l=!1,rangeEdge:a=null,current:s=!1,muted:c=!1,disabled:i=!1,focused:m=!1,className:d,onClick:h,onPointerEnter:p,onKeyDown:f}){return t("button",{type:"button",role:"gridcell","aria-label":o,"aria-selected":r,"aria-current":s?"date":void 0,"aria-disabled":i||void 0,tabIndex:m?0:-1,"data-focus-target":m?"true":void 0,className:[H,"start"===a?"rounded-s-mp-full":"end"===a?"rounded-e-mp-full":"middle"===a?"rounded-none":"rounded-mp-full",i?"bg-transparent cursor-default text-mp-on-surface/38":r?"bg-(--_mp-accent) text-(--_mp-on-accent)":l?"bg-(--_mp-accent-container) text-(--_mp-on-accent-container)":s?"bg-transparent border border-(--_mp-accent) text-(--_mp-accent)":c?"bg-transparent text-mp-on-surface-variant":"bg-transparent text-mp-on-surface",d??""].filter(Boolean).join(" "),onClick:()=>{i||h()},onPointerEnter:p,onKeyDown:f,children:[i?null:e(u,{}),n]})}function L({size:o,color:u,view:d,month:p,locale:f,labels:g,showPreviousButton:y,showNextButton:v,onStep:b,onViewChange:w}){const x=k(f,"long")[p.getMonth()],S=String(p.getFullYear()),M=D(f),N=R[o],P="day"===d?[g.previousMonth,g.nextMonth]:"month"===d?[g.previousYear,g.nextYear]:[g.previousYears,g.nextYears],_=(t,n)=>n?e(a,{size:N,color:u,label:P[-1===t?0:1],icon:e(l,{icon:-1===t?c:i,size:m[N],className:"rtl:rotate-180"}),onClick:()=>b(t)}):e("span",{"aria-hidden":"true",className:"size-(--_mp-cell)"}),C=t=>e(l,{icon:s,size:m[N],className:["transition-transform duration-(--mp-sys-motion-duration-short4)",t?"rotate-180":""].filter(Boolean).join(" ")}),j=e(r,{variant:"text",size:N,color:u,"aria-label":g.chooseMonth,"aria-expanded":"month"===d,endIcon:C("month"===d),onClick:()=>w("month"===d?"day":"month"),children:x},"month"),z=e(r,{variant:"text",size:N,color:u,className:"tabular-nums","aria-label":g.chooseYear,"aria-expanded":"year"===d,endIcon:C("year"===d),onClick:()=>w("year"===d?"day":"year"),children:S},"year"),A=Y(p.getFullYear());return t("div",{className:"flex items-center justify-between gap-1",children:[_(-1,y),e("div",{className:"flex min-w-0 flex-1 items-center justify-center gap-1",children:"year"===d?e("span",{className:`text-mp-on-surface flex h-(--_mp-cell) items-center tabular-nums ${h[o]}`,children:`${A}–${A+F-1}`}):"month"===d?z:t(n,M?{children:[j,z]}:{children:[z,j]})}),_(1,v)]})}export function Calendar({size:n,color:r,locale:l,weekStartsOn:a,month:s,onMonthChange:c,selected:i,rangeStart:u=null,rangeEnd:m=null,onSelect:d,onPreviewChange:h,minDate:p,maxDate:f,shouldDisableDate:v,showOutsideDays:b=!0,autoFocus:w=!1,showPreviousButton:D=!0,showNextButton:S=!0,precision:N="day",labels:C}){const[k,E]=o.useState(N),T=$[k]<$[N]?N:k,Y=o.useMemo(()=>i.filter(P),[i]),[R,H]=o.useState(()=>{const e=Y.find(e=>M(e,s));return e?j(e):M(A(),s)?A():z(s)}),K=o.useRef(w),U=o.useRef(null);o.useEffect(()=>{H(e=>M(e,s)?e:z(s))},[s]),o.useLayoutEffect(()=>{K.current&&(K.current=!1,U.current?.querySelector('[data-focus-target="true"]')?.focus({preventScroll:!0}))});const V=o.useCallback(e=>x(e,p,f)||(v?.(e)??!1),[p,f,v]),G=e=>{K.current=!0,E(e)},W=e=>{K.current=!0,c(e)};return t("div",{ref:U,className:"mp-calendar flex flex-col gap-1",style:{"--_mp-cell":B[n]},onPointerLeave:()=>h?.(null),children:[e(L,{size:n,color:r,view:T,month:s,locale:l,labels:C,showPreviousButton:D,showNextButton:S,onStep:e=>{c("day"===T?g(s,e):y(s,"month"===T?e:e*F))},onViewChange:G}),e("div",{className:"h-[calc(var(--_mp-cell)*7)] w-[calc(var(--_mp-cell)*7)]",children:"day"===T?e(I,{size:n,locale:l,weekStartsOn:a,month:s,chosen:Y,rangeStart:u,rangeEnd:m,focusedDate:R,showOutsideDays:b,isDisabled:V,onSelect:e=>{H(e),d(e)},onPreviewChange:h,onMoveFocus:e=>{K.current=!0,H(e),M(e,s)||c(z(e))}}):"month"===T?e(O,{size:n,locale:l,month:s,chosen:Y,minDate:p,maxDate:f,onMoveCursor:W,onPick:e=>{const t=_(s.getFullYear(),e,1);"month"!==N?(c(t),G("day")):d(t)}}):e(q,{size:n,month:s,chosen:Y,minDate:p,maxDate:f,onMoveCursor:W,onPick:e=>{"year"!==N?(c(_(e,s.getMonth(),1)),G("month")):d(_(e,0,1))}})})]})}function U(e){return"rtl"===getComputedStyle(e).direction?-1:1}function I({size:n,locale:r,weekStartsOn:l,month:a,chosen:s,rangeStart:c,rangeEnd:i,focusedDate:u,showOutsideDays:m,isDisabled:p,onSelect:y,onPreviewChange:x,onMoveFocus:D}){const N=E(r,l,"narrow"),_=E(r,l,"long"),C=(j=i,P(k=c)&&P(j)?b(k,j)<=0?[k,j]:[j,k]:null);var k,j;const z=A(),T=o.useMemo(()=>{const e=w(r,{dateStyle:"full"});return v(a,l).map(t=>t.map(t=>({date:t,label:e.format(t)})))},[a,l,r]),F=o.useRef(null),Y=o.useRef(a);o.useLayoutEffect(()=>{const e=F.current,t=Y.current;if(Y.current=a,!e||M(t,a))return;const n=t.getTime()<a.getTime(),o="rtl"===getComputedStyle(e).direction;e.style.setProperty("--_mp-calendar-from",String(n===o?-1:1)),e.dataset.mpPaged="true",e.style.animationName="none",e.offsetWidth,e.style.animationName=""},[a]);return t("div",{role:"grid","aria-label":w(r,{year:"numeric",month:"long"}).format(a),className:"flex h-full flex-col",children:[e("div",{role:"rowgroup",children:e("div",{role:"row",className:"grid grid-cols-7",children:N.map((t,n)=>e("span",{role:"columnheader","aria-label":_[n],className:`text-mp-on-surface-variant flex h-(--_mp-cell) items-center justify-center select-none ${d}`,children:t},n))})}),e("div",{ref:F,role:"rowgroup",className:"mp-calendar__page flex flex-1 flex-col",children:T.map((t,o)=>e("div",{role:"row",className:"grid grid-cols-7",children:t.map(({date:t,label:o})=>{const r=!M(t,a);if(r&&!m)return e("span",{role:"gridcell","aria-hidden":"true",className:"size-(--_mp-cell)"},t.getTime());const c=s.some(e=>S(e,t)),i=null!==C&&b(t,C[0])>=0&&b(t,C[1])<=0,d=null!==C&&i&&S(t,C[0]),v=null!==C&&i&&S(t,C[1]);return e(K,{label:o,selected:c,inRange:i&&!c,rangeEdge:i?d&&v?"both":d?"start":v?"end":"middle":null,current:S(t,z)&&!c,muted:r,disabled:p(t),focused:S(t,u),className:`size-(--_mp-cell) ${h[n]}`,onClick:()=>y(t),onPointerEnter:()=>x?.(t),onKeyDown:e=>((e,t)=>{const n=(t.getDay()-l+7)%7,o=U(e.currentTarget),r={ArrowLeft:()=>f(t,-o),ArrowRight:()=>f(t,o),ArrowUp:()=>f(t,-7),ArrowDown:()=>f(t,7),Home:()=>f(t,-n),End:()=>f(t,6-n),PageUp:()=>g(t,e.shiftKey?-12:-1),PageDown:()=>g(t,e.shiftKey?12:1)}[e.key];r&&(e.preventDefault(),D(r()))})(e,t),children:t.getDate()},t.getTime())})},o))})]})}function O({size:t,locale:n,month:r,chosen:l,minDate:a,maxDate:s,onMoveCursor:c,onPick:i}){const u=k(n,"short"),m=r.getFullYear(),d=new Date,p=o.useMemo(()=>{const e=w(n,{year:"numeric",month:"long"});return Array.from({length:12},(t,n)=>e.format(_(m,n,1)))},[n,m]),f=e=>{const t=U(e.currentTarget),n={ArrowLeft:-t,ArrowRight:t,ArrowUp:-3,ArrowDown:3,PageUp:-12,PageDown:12}[e.key];void 0!==n&&(e.preventDefault(),c(g(z(r),n)))};return e("div",{role:"grid","aria-label":String(m),className:"flex h-full flex-col justify-evenly",children:[0,1,2,3].map(n=>e("div",{role:"row",className:"grid grid-cols-3 gap-1",children:[0,1,2].map(o=>{const c=3*n+o;return e(K,{label:p[c],selected:l.some(e=>e.getFullYear()===m&&e.getMonth()===c),current:d.getFullYear()===m&&d.getMonth()===c,disabled:N(_(m,c,1),"month",a,s),focused:c===r.getMonth(),className:`h-(--_mp-cell) w-full ${h[t]}`,onClick:()=>i(c),onKeyDown:f,children:u[c]},c)})},n))})}function q({size:t,month:n,chosen:o,minDate:r,maxDate:l,onMoveCursor:a,onPick:s}){const c=Y(n.getFullYear()),i=(new Date).getFullYear(),u=e=>{const t=U(e.currentTarget),o={ArrowLeft:-t,ArrowRight:t,ArrowUp:-4,ArrowDown:4,PageUp:-F,PageDown:F}[e.key];void 0!==o&&(e.preventDefault(),a(y(z(n),o)))};return e("div",{role:"grid","aria-label":`${c}–${c+F-1}`,className:"flex h-full flex-col justify-evenly",children:[0,1,2].map(a=>e("div",{role:"row",className:"grid grid-cols-4 gap-1",children:[0,1,2,3].map(m=>{const d=c+4*a+m;return e(K,{label:String(d),selected:o.some(e=>e.getFullYear()===d),current:d===i,disabled:N(_(d,0,1),"year",r,l),focused:d===n.getFullYear(),className:`h-(--_mp-cell) w-full ${h[t]}`,onClick:()=>s(d),onKeyDown:u,children:d},d)})},a))})}function V(e,t){return Number.isFinite(e)?Math.min(t,Math.max(1,Math.round(e))):1}function G(e,t="auto"){const n=e.parentElement;if(!n)return;const o=e.getBoundingClientRect(),r=n.getBoundingClientRect(),l=o.top-r.top-n.clientTop+n.scrollTop,a=l+o.height;l<n.scrollTop?n.scrollTo({top:l,behavior:t}):a>n.scrollTop+n.clientHeight&&n.scrollTo({top:a-n.clientHeight,behavior:t})}export function MPTimeGrid({size:n,locale:r,value:l,referenceDate:a,onChange:s,hour12:c,showSeconds:i,hourStep:m,minuteStep:d,secondStep:f,shouldDisableTime:g,autoFocus:y=!1,labels:v}){const b=l??a,x=o.useRef(null),[D,S]=o.useMemo(()=>C(r),[r]);o.useEffect(()=>{const e=x.current;if(e?.querySelectorAll('[data-chosen="true"]').forEach(e=>G(e,"instant")),y){const t=e?.querySelector('[role="listbox"]');(t?.querySelector('[data-chosen="true"]')??t?.querySelector('[role="option"]'))?.focus({preventScroll:!0})}},[y]);const M=o.useMemo(()=>{const e=c?12:24,t=V(m,e),n=Array.from({length:Math.ceil(e/t)},(e,n)=>n*t);return c?n.map(e=>0===e?12:e):n},[c,m]),N=o.useMemo(()=>{const e=V(d,60);return Array.from({length:Math.ceil(60/e)},(t,n)=>n*e)},[d]),P=o.useMemo(()=>{const e=V(f,60);return Array.from({length:Math.ceil(60/e)},(t,n)=>n*e)},[f]),_=e=>String(e).padStart(2,"0"),k=c?b.getHours()%12||12:b.getHours(),[j,z]=o.useState({}),A=(o,r,a,i,m)=>{const d=null===l?-1:a.findIndex(e=>i(e)),p=j[o]??(d>=0?d:0);return e("div",{role:"listbox","aria-label":r,className:["mp-time-grid__column flex flex-col gap-0.5 overflow-y-auto overscroll-contain","motion-safe:scroll-smooth","h-[calc(var(--_mp-cell)*7)] w-[calc(var(--_mp-cell)*1.75)]","scroll-py-0.5 [scrollbar-width:thin]"].join(" "),onKeyDown:e=>{const t={ArrowDown:1,ArrowUp:-1,PageDown:5,PageUp:-5}[e.key],n=void 0!==t?(e=>{const t=[...e.children].indexOf(document.activeElement);return t>=0?t:p})(e.currentTarget)+t:"Home"===e.key?0:"End"===e.key?a.length-1:null;null!==n&&(e.preventDefault(),((e,t)=>{const n=Math.min(a.length-1,Math.max(0,e)),r=t.children[n];z(e=>({...e,[o]:n})),r instanceof HTMLElement&&(r.focus({preventScroll:!0}),G(r))})(n,e.currentTarget))},children:a.map((r,a)=>{const d=((e,t)=>T(b,"hour"===e?{hours:c?t%12+(b.getHours()>=12?12:0):t}:"minute"===e?{minutes:t}:"second"===e?{seconds:t}:{hours:b.getHours()%12+12*t}))(o,r),f=null!==l&&i(r),y=g?.(d,o)??!1;return t("button",{type:"button",role:"option","aria-selected":f,"aria-disabled":y||void 0,"data-chosen":f?"true":void 0,tabIndex:a===p?0:-1,className:[H,"rounded-mp-full h-(--_mp-cell) w-full shrink-0",h[n],y?"bg-transparent cursor-default text-mp-on-surface/38":f?"bg-(--_mp-accent) text-(--_mp-on-accent)":"bg-transparent text-mp-on-surface"].join(" "),onFocus:()=>z(e=>({...e,[o]:a})),onClick:()=>{y||s(d)},children:[y?null:e(u,{}),m(r)]},r)})},o)};return t("div",{ref:x,className:"mp-time-grid flex gap-1",style:{"--_mp-cell":B[n]},children:[A("hour",v.hour,M,e=>e===k,e=>c?String(e):_(e)),A("minute",v.minute,N,e=>e===b.getMinutes(),_),i?A("second",v.second,P,e=>e===b.getSeconds(),_):null,c?A("meridiem",v.meridiem,[0,1],e=>(b.getHours()>=12?1:0)===e,e=>0===e?D:S):null,e("span",{className:p,"aria-live":"polite",children:null===l?"":w(r,{hour:"numeric",minute:"2-digit",...i?{second:"2-digit"}:{}}).format(l)})]})}
|
|
2
|
+
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import*as o from"react";import{MPButton as r}from"../components/button/MPButton.js";import{MPIcon as l}from"../components/icon/MPIcon.js";import{MPIconButton as a}from"../components/icon-button/MPIconButton.js";import{ChevronDownIcon as s,ChevronLeftIcon as c,ChevronRightIcon as i}from"../constants/icons.js";import{MPStateLayer as u}from"./StateLayer.js";import{CONTROL_ICON as m,META_TEXT as d,PROSE_TEXT as h}from"./scale.js";import{VISUALLY_HIDDEN as p}from"./visually-hidden.js";import{addDays as f,addMonths as g,addYears as b,calendarWeeks as y,compareDay as v,dateFormatter as w,isDayOutside as x,isMonthBeforeYear as D,isSameDay as S,isSameMonth as M,isUnitOutside as N,isValidDate as P,makeDate as _,meridiemLabels as C,monthLabels as k,startOfDay as j,startOfMonth as z,today as A,weekdayLabels as E,withTime as T,YEAR_PAGE_SIZE as F,yearPageStart as Y}from"./date.js";const B={xs:"1.75rem",sm:"2rem",md:"2.5rem",lg:"2.75rem",xl:"3rem"},R={xs:"xs",sm:"xs",md:"sm",lg:"sm",xl:"md"},H=/*@__PURE__*/["group relative flex cursor-pointer items-center justify-center overflow-hidden","box-border appearance-none p-0 font-[inherit] tabular-nums select-none","transition-[background-color,border-color,color]","duration-(--mp-sys-motion-duration-short4)","outline-mp-secondary focus-visible:z-10 focus-visible:outline-2","focus-visible:outline-offset-[-2px] focus-visible:outline-solid outline-none"].join(" "),$={day:0,month:1,year:2};function K({children:n,label:o,selected:r,inRange:l=!1,rangeEdge:a=null,current:s=!1,muted:c=!1,disabled:i=!1,focused:m=!1,className:d,onClick:h,onPointerEnter:p,onKeyDown:f}){return t("button",{type:"button",role:"gridcell","aria-label":o,"aria-selected":r,"aria-current":s?"date":void 0,"aria-disabled":i||void 0,tabIndex:m?0:-1,"data-focus-target":m?"true":void 0,className:[H,"start"===a?"rounded-s-mp-full":"end"===a?"rounded-e-mp-full":"middle"===a?"rounded-none":"rounded-mp-full",i?"border-0 bg-transparent cursor-default text-mp-on-surface/38":r?"border-0 bg-(--_mp-accent) text-(--_mp-on-accent)":l?"border-0 bg-(--_mp-accent-container) text-(--_mp-on-accent-container)":s?"bg-transparent border border-(--_mp-accent) text-(--_mp-accent)":c?"border-0 bg-transparent text-mp-on-surface-variant":"border-0 bg-transparent text-mp-on-surface",d??""].filter(Boolean).join(" "),onClick:()=>{i||h()},onPointerEnter:p,onKeyDown:f,children:[i?null:e(u,{}),n]})}function L({size:o,color:u,view:d,month:p,locale:f,labels:g,showPreviousButton:b,showNextButton:y,onStep:v,onViewChange:w}){const x=k(f,"long")[p.getMonth()],S=String(p.getFullYear()),M=D(f),N=R[o],P="day"===d?[g.previousMonth,g.nextMonth]:"month"===d?[g.previousYear,g.nextYear]:[g.previousYears,g.nextYears],_=(t,n)=>n?e(a,{size:N,color:u,label:P[-1===t?0:1],icon:e(l,{icon:-1===t?c:i,size:m[N],className:"rtl:rotate-180"}),onClick:()=>v(t)}):e("span",{"aria-hidden":"true",className:"size-(--_mp-cell)"}),C=t=>e(l,{icon:s,size:m[N],className:["transition-transform duration-(--mp-sys-motion-duration-short4)",t?"rotate-180":""].filter(Boolean).join(" ")}),j=e(r,{variant:"text",size:N,color:u,"aria-label":g.chooseMonth,"aria-expanded":"month"===d,endIcon:C("month"===d),onClick:()=>w("month"===d?"day":"month"),children:x},"month"),z=e(r,{variant:"text",size:N,color:u,className:"tabular-nums","aria-label":g.chooseYear,"aria-expanded":"year"===d,endIcon:C("year"===d),onClick:()=>w("year"===d?"day":"year"),children:S},"year"),A=Y(p.getFullYear());return t("div",{className:"flex items-center justify-between gap-1",children:[_(-1,b),e("div",{className:"flex min-w-0 flex-1 items-center justify-center gap-1",children:"year"===d?e("span",{className:`text-mp-on-surface flex h-(--_mp-cell) items-center tabular-nums ${h[o]}`,children:`${A}–${A+F-1}`}):"month"===d?z:t(n,M?{children:[j,z]}:{children:[z,j]})}),_(1,y)]})}export function Calendar({size:n,color:r,locale:l,weekStartsOn:a,month:s,onMonthChange:c,selected:i,rangeStart:u=null,rangeEnd:m=null,onSelect:d,onPreviewChange:h,minDate:p,maxDate:f,shouldDisableDate:y,showOutsideDays:v=!0,autoFocus:w=!1,showPreviousButton:D=!0,showNextButton:S=!0,precision:N="day",labels:C}){const[k,E]=o.useState(N),T=$[k]<$[N]?N:k,Y=o.useMemo(()=>i.filter(P),[i]),[R,H]=o.useState(()=>{const e=Y.find(e=>M(e,s));return e?j(e):M(A(),s)?A():z(s)}),K=o.useRef(w),U=o.useRef(null);o.useEffect(()=>{H(e=>M(e,s)?e:z(s))},[s]),o.useLayoutEffect(()=>{K.current&&(K.current=!1,U.current?.querySelector('[data-focus-target="true"]')?.focus({preventScroll:!0}))});const V=o.useCallback(e=>x(e,p,f)||(y?.(e)??!1),[p,f,y]),G=e=>{K.current=!0,E(e)},W=e=>{K.current=!0,c(e)};return t("div",{ref:U,className:"mp-calendar flex flex-col gap-1",style:{"--_mp-cell":B[n]},onPointerLeave:()=>h?.(null),children:[e(L,{size:n,color:r,view:T,month:s,locale:l,labels:C,showPreviousButton:D,showNextButton:S,onStep:e=>{c("day"===T?g(s,e):b(s,"month"===T?e:e*F))},onViewChange:G}),e("div",{className:"h-[calc(var(--_mp-cell)*7)] w-[calc(var(--_mp-cell)*7)]",children:"day"===T?e(I,{size:n,locale:l,weekStartsOn:a,month:s,chosen:Y,rangeStart:u,rangeEnd:m,focusedDate:R,showOutsideDays:v,isDisabled:V,onSelect:e=>{H(e),d(e)},onPreviewChange:h,onMoveFocus:e=>{K.current=!0,H(e),M(e,s)||c(z(e))}}):"month"===T?e(O,{size:n,locale:l,month:s,chosen:Y,minDate:p,maxDate:f,onMoveCursor:W,onPick:e=>{const t=_(s.getFullYear(),e,1);"month"!==N?(c(t),G("day")):d(t)}}):e(q,{size:n,month:s,chosen:Y,minDate:p,maxDate:f,onMoveCursor:W,onPick:e=>{"year"!==N?(c(_(e,s.getMonth(),1)),G("month")):d(_(e,0,1))}})})]})}function U(e){return"rtl"===getComputedStyle(e).direction?-1:1}function I({size:n,locale:r,weekStartsOn:l,month:a,chosen:s,rangeStart:c,rangeEnd:i,focusedDate:u,showOutsideDays:m,isDisabled:p,onSelect:b,onPreviewChange:x,onMoveFocus:D}){const N=E(r,l,"narrow"),_=E(r,l,"long"),C=(j=i,P(k=c)&&P(j)?v(k,j)<=0?[k,j]:[j,k]:null);var k,j;const z=A(),T=o.useMemo(()=>{const e=w(r,{dateStyle:"full"});return y(a,l).map(t=>t.map(t=>({date:t,label:e.format(t)})))},[a,l,r]),F=o.useRef(null),Y=o.useRef(a);o.useLayoutEffect(()=>{const e=F.current,t=Y.current;if(Y.current=a,!e||M(t,a))return;const n=t.getTime()<a.getTime(),o="rtl"===getComputedStyle(e).direction;e.style.setProperty("--_mp-calendar-from",String(n===o?-1:1)),e.dataset.mpPaged="true",e.style.animationName="none",e.offsetWidth,e.style.animationName=""},[a]);return t("div",{role:"grid","aria-label":w(r,{year:"numeric",month:"long"}).format(a),className:"flex h-full flex-col",children:[e("div",{role:"rowgroup",children:e("div",{role:"row",className:"grid grid-cols-7",children:N.map((t,n)=>e("span",{role:"columnheader","aria-label":_[n],className:`text-mp-on-surface-variant flex h-(--_mp-cell) items-center justify-center select-none ${d}`,children:t},n))})}),e("div",{ref:F,role:"rowgroup",className:"mp-calendar__page flex flex-1 flex-col",children:T.map((t,o)=>e("div",{role:"row",className:"grid grid-cols-7",children:t.map(({date:t,label:o})=>{const r=!M(t,a);if(r&&!m)return e("span",{role:"gridcell","aria-hidden":"true",className:"size-(--_mp-cell)"},t.getTime());const c=s.some(e=>S(e,t)),i=null!==C&&v(t,C[0])>=0&&v(t,C[1])<=0,d=null!==C&&i&&S(t,C[0]),y=null!==C&&i&&S(t,C[1]);return e(K,{label:o,selected:c,inRange:i&&!c,rangeEdge:i?d&&y?"both":d?"start":y?"end":"middle":null,current:S(t,z)&&!c,muted:r,disabled:p(t),focused:S(t,u),className:`size-(--_mp-cell) ${h[n]}`,onClick:()=>b(t),onPointerEnter:()=>x?.(t),onKeyDown:e=>((e,t)=>{const n=(t.getDay()-l+7)%7,o=U(e.currentTarget),r={ArrowLeft:()=>f(t,-o),ArrowRight:()=>f(t,o),ArrowUp:()=>f(t,-7),ArrowDown:()=>f(t,7),Home:()=>f(t,-n),End:()=>f(t,6-n),PageUp:()=>g(t,e.shiftKey?-12:-1),PageDown:()=>g(t,e.shiftKey?12:1)}[e.key];r&&(e.preventDefault(),D(r()))})(e,t),children:t.getDate()},t.getTime())})},o))})]})}function O({size:t,locale:n,month:r,chosen:l,minDate:a,maxDate:s,onMoveCursor:c,onPick:i}){const u=k(n,"short"),m=r.getFullYear(),d=new Date,p=o.useMemo(()=>{const e=w(n,{year:"numeric",month:"long"});return Array.from({length:12},(t,n)=>e.format(_(m,n,1)))},[n,m]),f=e=>{const t=U(e.currentTarget),n={ArrowLeft:-t,ArrowRight:t,ArrowUp:-3,ArrowDown:3,PageUp:-12,PageDown:12}[e.key];void 0!==n&&(e.preventDefault(),c(g(z(r),n)))};return e("div",{role:"grid","aria-label":String(m),className:"flex h-full flex-col justify-evenly",children:[0,1,2,3].map(n=>e("div",{role:"row",className:"grid grid-cols-3 gap-1",children:[0,1,2].map(o=>{const c=3*n+o;return e(K,{label:p[c],selected:l.some(e=>e.getFullYear()===m&&e.getMonth()===c),current:d.getFullYear()===m&&d.getMonth()===c,disabled:N(_(m,c,1),"month",a,s),focused:c===r.getMonth(),className:`h-(--_mp-cell) w-full ${h[t]}`,onClick:()=>i(c),onKeyDown:f,children:u[c]},c)})},n))})}function q({size:t,month:n,chosen:o,minDate:r,maxDate:l,onMoveCursor:a,onPick:s}){const c=Y(n.getFullYear()),i=(new Date).getFullYear(),u=e=>{const t=U(e.currentTarget),o={ArrowLeft:-t,ArrowRight:t,ArrowUp:-4,ArrowDown:4,PageUp:-F,PageDown:F}[e.key];void 0!==o&&(e.preventDefault(),a(b(z(n),o)))};return e("div",{role:"grid","aria-label":`${c}–${c+F-1}`,className:"flex h-full flex-col justify-evenly",children:[0,1,2].map(a=>e("div",{role:"row",className:"grid grid-cols-4 gap-1",children:[0,1,2,3].map(m=>{const d=c+4*a+m;return e(K,{label:String(d),selected:o.some(e=>e.getFullYear()===d),current:d===i,disabled:N(_(d,0,1),"year",r,l),focused:d===n.getFullYear(),className:`h-(--_mp-cell) w-full ${h[t]}`,onClick:()=>s(d),onKeyDown:u,children:d},d)})},a))})}function V(e,t){return Number.isFinite(e)?Math.min(t,Math.max(1,Math.round(e))):1}function G(e,t="auto"){const n=e.parentElement;if(!n)return;const o=e.getBoundingClientRect(),r=n.getBoundingClientRect(),l=o.top-r.top-n.clientTop+n.scrollTop,a=l+o.height;l<n.scrollTop?n.scrollTo({top:l,behavior:t}):a>n.scrollTop+n.clientHeight&&n.scrollTo({top:a-n.clientHeight,behavior:t})}export function MPTimeGrid({size:n,locale:r,value:l,referenceDate:a,onChange:s,hour12:c,showSeconds:i,hourStep:m,minuteStep:d,secondStep:f,shouldDisableTime:g,autoFocus:b=!1,labels:y}){const v=l??a,x=o.useRef(null),[D,S]=o.useMemo(()=>C(r),[r]);o.useEffect(()=>{const e=x.current;if(e?.querySelectorAll('[data-chosen="true"]').forEach(e=>G(e,"instant")),b){const t=e?.querySelector('[role="listbox"]');(t?.querySelector('[data-chosen="true"]')??t?.querySelector('[role="option"]'))?.focus({preventScroll:!0})}},[b]);const M=o.useMemo(()=>{const e=c?12:24,t=V(m,e),n=Array.from({length:Math.ceil(e/t)},(e,n)=>n*t);return c?n.map(e=>0===e?12:e):n},[c,m]),N=o.useMemo(()=>{const e=V(d,60);return Array.from({length:Math.ceil(60/e)},(t,n)=>n*e)},[d]),P=o.useMemo(()=>{const e=V(f,60);return Array.from({length:Math.ceil(60/e)},(t,n)=>n*e)},[f]),_=e=>String(e).padStart(2,"0"),k=c?v.getHours()%12||12:v.getHours(),[j,z]=o.useState({}),A=(o,r,a,i,m)=>{const d=null===l?-1:a.findIndex(e=>i(e)),p=j[o]??(d>=0?d:0);return e("div",{role:"listbox","aria-label":r,className:["mp-time-grid__column flex flex-col gap-0.5 overflow-y-auto overscroll-contain","motion-safe:scroll-smooth","h-[calc(var(--_mp-cell)*7)] w-[calc(var(--_mp-cell)*1.75)]","scroll-py-0.5 [scrollbar-width:thin]"].join(" "),onKeyDown:e=>{const t={ArrowDown:1,ArrowUp:-1,PageDown:5,PageUp:-5}[e.key],n=void 0!==t?(e=>{const t=[...e.children].indexOf(document.activeElement);return t>=0?t:p})(e.currentTarget)+t:"Home"===e.key?0:"End"===e.key?a.length-1:null;null!==n&&(e.preventDefault(),((e,t)=>{const n=Math.min(a.length-1,Math.max(0,e)),r=t.children[n];z(e=>({...e,[o]:n})),r instanceof HTMLElement&&(r.focus({preventScroll:!0}),G(r))})(n,e.currentTarget))},children:a.map((r,a)=>{const d=((e,t)=>T(v,"hour"===e?{hours:c?t%12+(v.getHours()>=12?12:0):t}:"minute"===e?{minutes:t}:"second"===e?{seconds:t}:{hours:v.getHours()%12+12*t}))(o,r),f=null!==l&&i(r),b=g?.(d,o)??!1;return t("button",{type:"button",role:"option","aria-selected":f,"aria-disabled":b||void 0,"data-chosen":f?"true":void 0,tabIndex:a===p?0:-1,className:[H,"rounded-mp-full h-(--_mp-cell) w-full shrink-0 border-0",h[n],b?"bg-transparent cursor-default text-mp-on-surface/38":f?"bg-(--_mp-accent) text-(--_mp-on-accent)":"bg-transparent text-mp-on-surface"].join(" "),onFocus:()=>z(e=>({...e,[o]:a})),onClick:()=>{b||s(d)},children:[b?null:e(u,{}),m(r)]},r)})},o)};return t("div",{ref:x,className:"mp-time-grid flex gap-1",style:{"--_mp-cell":B[n]},children:[A("hour",y.hour,M,e=>e===k,e=>c?String(e):_(e)),A("minute",y.minute,N,e=>e===v.getMinutes(),_),i?A("second",y.second,P,e=>e===v.getSeconds(),_):null,c?A("meridiem",y.meridiem,[0,1],e=>(v.getHours()>=12?1:0)===e,e=>0===e?D:S):null,e("span",{className:p,"aria-live":"polite",children:null===l?"":w(r,{hour:"numeric",minute:"2-digit",...i?{second:"2-digit"}:{}}).format(l)})]})}
|
|
@@ -74,12 +74,6 @@ export interface Visibility {
|
|
|
74
74
|
export declare function useVisibility(series: readonly {
|
|
75
75
|
hidden?: boolean;
|
|
76
76
|
}[]): Visibility;
|
|
77
|
-
export declare const LEGEND_SIDE: {
|
|
78
|
-
readonly top: "flex-col-reverse";
|
|
79
|
-
readonly bottom: "flex-col";
|
|
80
|
-
readonly left: "flex-row-reverse";
|
|
81
|
-
readonly right: "flex-row";
|
|
82
|
-
};
|
|
83
77
|
interface LegendProps {
|
|
84
78
|
/**
|
|
85
79
|
* What each entry is called. Names rather than series, because a pie's
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as e,Fragment as t,jsxs as l}from"react/jsx-runtime";import*as n from"react";import{VISUALLY_HIDDEN as a}from"./visually-hidden.js";import{cssLength as r}from"./length.js";import{PLOT_HEIGHT as i,formatCategory as s}from"./chart.js";export function useVisibility(e){const[t,l]=n.useState(()=>{const t=new Set;return e.forEach((e,l)=>{e.hidden&&t.add(l)}),t}),[a,r]=n.useState(null),i=n.useCallback(e=>{l(t=>{const l=new Set(t);return l.has(e)?l.delete(e):l.add(e),l})},[]);return{visible:e.map((e,l)=>!t.has(l)),hovered:a,toggle:i,setHovered:r}}
|
|
2
|
+
import{jsx as e,Fragment as t,jsxs as l}from"react/jsx-runtime";import*as n from"react";import{VISUALLY_HIDDEN as a}from"./visually-hidden.js";import{cssLength as r}from"./length.js";import{PLOT_HEIGHT as i,formatCategory as s}from"./chart.js";export function useVisibility(e){const[t,l]=n.useState(()=>{const t=new Set;return e.forEach((e,l)=>{e.hidden&&t.add(l)}),t}),[a,r]=n.useState(null),i=n.useCallback(e=>{l(t=>{const l=new Set(t);return l.has(e)?l.delete(e):l.add(e),l})},[]);return{visible:e.map((e,l)=>!t.has(l)),hovered:a,toggle:i,setHovered:r}}const o={top:"flex-col-reverse",bottom:"flex-col",left:"flex-row-reverse",right:"flex-row"},c={start:"justify-start",center:"justify-center",end:"justify-end"};export function ChartLegend({names:n,colors:a,options:r,visibility:i,size:s,values:o,swatch:m}){const d=!1!==r.interactive,p="xs"===s||"sm"===s?"text-mp-label-small":"text-mp-label-medium";return e("ul",{className:["mp-chart__legend m-0 flex list-none flex-wrap items-center gap-x-4 gap-y-1 p-0",c[r.align??"center"],p].join(" "),children:n.map((n,r)=>{const s=i.visible[r],c=!s||null!==i.hovered&&i.hovered!==r,p=n??`${r+1}`,u=l(t,{children:[e("span",{className:"shrink-0","aria-hidden":"true",children:m?m(r,a[r]):e("span",{className:"block size-2.5 rounded-mp-full",style:{background:a[r]}})}),e("span",{className:"text-mp-on-surface-variant truncate",children:p}),o?.[r]?e("span",{className:"text-mp-on-surface tabular-nums",children:o[r]}):null]});return e("li",{className:"min-w-0",children:d?e("button",{type:"button","aria-pressed":s,onClick:()=>i.toggle(r),onPointerEnter:()=>i.setHovered(r),onPointerLeave:()=>i.setHovered(null),onFocus:()=>i.setHovered(r),onBlur:()=>i.setHovered(null),className:["flex min-w-0 cursor-pointer items-center gap-1.5 rounded-mp-xs","appearance-none border-0 bg-transparent p-0 text-inherit [font:inherit]","focus-visible:outline-mp-primary focus-visible:outline-2 focus-visible:outline-offset-2",c?"opacity-40":"",s?"":"line-through"].filter(Boolean).join(" "),children:u}):e("span",{className:"flex min-w-0 items-center gap-1.5 "+(c?"opacity-40":""),children:u})},r)})})}export function ChartTooltipPanel({heading:t,items:n,x:a,y:r,flip:i,size:s}){return l("div",{"aria-hidden":"true",className:["mp-chart__tooltip pointer-events-none absolute z-10 min-w-24 max-w-64","bg-mp-surface-container-high shadow-mp-2 rounded-mp-xs px-2.5 py-2","xs"===s||"sm"===s?"text-mp-label-small":"text-mp-label-medium"].join(" "),style:{left:a,top:r,transform:`translate(${i?"calc(-100% - 12px)":"12px"}, -50%)`},children:[null==t||""===t?null:e("div",{className:"text-mp-on-surface-variant mb-1 truncate",children:t}),e("ul",{className:"m-0 flex list-none flex-col gap-0.5 p-0",children:n.map(t=>l("li",{className:"flex items-center gap-1.5",children:[e("span",{"aria-hidden":"true",className:"block size-2 shrink-0 rounded-mp-full",style:{background:t.color}}),t.name?e("span",{className:"text-mp-on-surface-variant min-w-0 truncate",children:t.name}):null,e("span",{className:"text-mp-on-surface ms-auto ps-2 tabular-nums",children:t.label??t.formatted})]},t.seriesIndex))})]})}export function ChartStatus({heading:r,items:i}){return e("span",{role:"status","aria-live":"polite",className:a,children:0===i.length?null:l(t,{children:[null==r||""===r?null:l(t,{children:[r,", "]}),i.map((e,t)=>l(n.Fragment,{children:[t>0?", ":null,e.name?`${e.name}: `:null,e.label??e.formatted]},e.seriesIndex))]})})}export function ChartTable({id:t,caption:n,corner:r,categories:i,names:o,values:c,format:m,locale:d,empty:p}){return e("div",{id:t,className:a,children:l("table",{children:[e("caption",{children:n}),e("thead",{children:l("tr",{children:[e("th",{scope:"col",children:r}),o.map((t,l)=>e("th",{scope:"col",children:t??l+1},l))]})}),e("tbody",{children:0===i.length?e("tr",{children:e("td",{colSpan:o.length+1,children:p})}):i.map((t,n)=>l("tr",{children:[e("th",{scope:"row",children:s(t,d)}),o.map((t,l)=>{const a=c[l]?.[n];return e("td",{children:a?.label??(null===a?.value||void 0===a?p:m(a.value))},l)})]},n))})]})})}export function ChartShell({size:t,plotRef:n,name:a,describedBy:s,interactive:c,height:m,plotProps:d,children:p,tooltip:u,legend:h,legendSide:f="bottom",status:x,table:b,className:v,...g}){return l("div",{"data-mp-size":t,className:["mp-chart flex min-w-0 flex-col gap-3",v??""].filter(Boolean).join(" "),...g,children:[l("div",{className:`flex min-w-0 gap-3 ${o[f]}`,children:[l("div",{ref:n,role:"img",tabIndex:c?0:void 0,"aria-label":a,"aria-describedby":s,...d,className:["mp-chart__plot rounded-mp-xs relative min-w-0 flex-1","focus-visible:outline-mp-primary focus-visible:outline-2 focus-visible:outline-offset-2"].join(" "),style:{height:r(m)??i[t]},children:[p,u]}),h]}),e(ChartStatus,{heading:x.heading,items:x.items}),b]})}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as r,Fragment as t,jsxs as
|
|
2
|
+
import{jsx as r,Fragment as t,jsxs as e}from"react/jsx-runtime";import*as o from"react";import{Field as a}from"@base-ui/react/field";import{PROSE_TEXT as n}from"./scale.js";const i={xs:"start-1",sm:"start-2",md:"start-3",lg:"start-3",xl:"start-4"},s={xs:"top-[18px]",sm:"top-[18px]",md:"top-5",lg:"top-5",xl:"top-5"};function d(o,a){return e(t,{children:[o,a?r("span",{"aria-hidden":"true",children:" *"}):null]})}export function MPFieldOutline({label:t,required:e=!1,notched:o=!0}){return r("fieldset",{"aria-hidden":"true",className:["pointer-events-none absolute inset-0 m-0 min-w-0 px-2 pt-0",t?"-top-[5px]":"","text-start","rounded-mp-xs border border-mp-outline","transition-[border-color] duration-(--mp-sys-motion-duration-short4)","group-hover:border-mp-on-surface","group-focus-within:border-2 group-focus-within:border-mp-primary","group-data-focused:border-2 group-data-focused:border-mp-primary","group-data-invalid:border-mp-error","group-data-disabled:border-mp-on-surface/12"].filter(Boolean).join(" "),children:t?r("legend",{className:["text-mp-body-small invisible float-none block h-[11px] w-auto overflow-hidden p-0","leading-none","ease-mp-standard transition-[max-width,padding]","duration-(--mp-sys-motion-duration-short4)",o?"max-w-full px-1":"max-w-0 px-0"].join(" "),children:d(t,e)}):null})}export function MPFieldLabel({size:t,label:e,required:o=!1,htmlFor:p,shrunk:l=!0,multiline:u=!1}){return r(a.Label,{htmlFor:p,"data-mp-shrunk":l?"":void 0,className:["text-mp-on-surface-variant","ease-mp-standard transition-[color,top,font-size,max-width]","duration-(--mp-sys-motion-duration-short4)","pointer-events-none absolute -translate-y-1/2 px-1 leading-none",i[t],l?"text-mp-body-small top-0 max-w-none":[n[t],"max-w-[calc(100%-2rem)] truncate",u?s[t]:"top-1/2"].join(" "),"group-focus-within:text-mp-primary","group-data-focused:text-mp-primary","group-data-invalid:text-mp-error","group-data-disabled:text-mp-on-surface/38"].join(" "),children:d(e,o)})}export function useFloatingLabel({floating:r,filled:t,pinned:e=!1}){const[a,n]=o.useState(!1);return{shrunk:!r||t||a||e,focusProps:{onFocusCapture:()=>n(!0),onBlurCapture:r=>{r.currentTarget.contains(r.relatedTarget)||n(!1)}}}}
|
package/dist/internal/Picker.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as e,jsxs as n}from"react/jsx-runtime";import*as o from"react";import{Field as r}from"@base-ui/react/field";import{Popover as i}from"@base-ui/react/popover";import{MPIcon as t}from"../components/icon/MPIcon.js";import{CloseIcon as l}from"../constants/icons.js";import{accentSlots as s}from"./accent.js";import{MPFieldLabel as a,MPFieldOutline as p,useFloatingLabel as c}from"./FieldOutline.js";import{MPStateLayer as u}from"./StateLayer.js";import{MPSupportingText as m}from"./SupportingText.js";import{MPWidthSizer as d}from"./WidthSizer.js";import{displaySamples as f}from"./date.js";import{CONTROL_ICON as h,hasContent as x,PROSE_TEXT as g}from"./scale.js";import{FADE as b,PORTAL_LAYER as y}from"./surface.js";export function useDisplaySamples(e,n){const r=`${e??""} ${JSON.stringify(n)}`;return o.useMemo(()=>f(e,n),[r])}const j={xs:{padding:"px-2",height:"h-8"},sm:{padding:"px-3",height:"h-10"},md:{padding:"px-4",height:"h-14"},lg:{padding:"px-4",height:"h-16"},xl:{padding:"px-5",height:"h-18"}};export const POPUP_PAD={xs:"p-1.5",sm:"p-2",md:"p-2.5",lg:"p-3",xl:"p-3.5"};export function MPPickerShell({slug:f,size:v="md",color:P="primary",fullWidth:N=!1,label:k,floatingLabel:w=!0,description:C,errorMessage:O,startIcon:M,required:D=!1,disabled:F=!1,readOnly:S=!1,id:z,className:B,style:_,onKeyDown:I,onKeyUp:K,onFocus:R,onBlur:U,onClick:$,onDoubleClick:q,onContextMenu:T,display:A,samples:E,empty:L,clearable:W=!1,onClear:J,open:V,onOpenChange:Z,labels:G,hiddenValues:H,children:Q,triggerRef:X}){const Y=x(O),ee=j[v],ne=o.useId(),oe=z??ne,re=W&&!L&&!(F||S),{shrunk:ie,focusProps:te}=c({floating:w&&x(k),filled:!L,pinned:V||x(M)});return n(r.Root,{disabled:F,invalid:Y,"data-mp-size":v,className:[`mp-${f} group flex-col align-top`,N?"flex w-full":"inline-flex w-fit",B??""].filter(Boolean).join(" "),style:{...s(P),..._},...te,children:[n(i.Root,{open:V,onOpenChange:Z,children:[n("div",{className:"relative w-full",children:[n(i.Trigger,{id:oe,ref:X,disabled:F,nativeButton:!0,onKeyDown:I,onKeyUp:K,onFocus:R,onBlur:U,onClick:$,onDoubleClick:q,onContextMenu:T,className:["relative flex w-full items-center gap-2 select-none","appearance-none bg-transparent font-[inherit] outline-none",ee.padding,re?"pe-10":"",ee.height,g[v],F?"text-mp-on-surface/38 cursor-default":"text-mp-on-surface "+(S?"cursor-default":"cursor-pointer")].filter(Boolean).join(" "),children:[M?e("span",{className:["flex shrink-0 items-center",F?"text-mp-on-surface/38":"text-mp-on-surface-variant"].join(" "),children:M}):null,n("span",{className:"flex min-w-0 flex-1 flex-col",children:[e("span",{className:["w-full truncate text-start",L&&!F?"text-mp-on-surface-variant":""].filter(Boolean).join(" "),children:L&&!ie?null:A}),e(d,{samples:E??[]})]})]}),re?n("button",{type:"button","aria-label":G.clear,onClick:J,className:["group/clear rounded-mp-full text-mp-on-surface-variant absolute inset-y-0","end-1 my-auto flex size-8 cursor-pointer items-center justify-center","appearance-none border-0 bg-transparent font-[inherit]","outline-mp-secondary focus-visible:outline-2 focus-visible:outline-offset-1","focus-visible:outline-solid outline-none"].join(" "),children:[e(u,{className:"group-hover/clear:opacity-8 group-focus-visible/clear:opacity-10"}),e(t,{icon:l,size:h[v]})]}):null,e(p,{label:k,required:D,notched:ie}),x(k)?e(a,{size:v,label:k,required:D,htmlFor:oe,shrunk:ie}):null]}),e(i.Portal,{children:e(i.Positioner,{className:y,sideOffset:4,align:"start",children:e(i.Popup,{initialFocus:!1,style:s(P),className:[`mp-${f}__popup rounded-mp-md shadow-mp-2 bg-mp-surface-container`,"text-mp-on-surface outline-none",POPUP_PAD[v],g[v],b].join(" "),children:Q})})})]}),e(m,{description:C,errorMessage:O,className:ee.padding}),H?.map((n,o)=>e("input",{type:"hidden",name:n.name,value:n.value},o))]})}export function MPPickerFooter({children:n}){return e("div",{className:"border-mp-outline-variant flex items-center justify-end gap-1 border-t pt-1.5",children:n})}export function MPPickerDivider(){return e("div",{"aria-hidden":"true",className:"bg-mp-outline-variant w-px self-stretch"})}export const FOOTER_SIZE={xs:"xs",sm:"xs",md:"sm",lg:"sm",xl:"md"};
|
|
2
|
+
import{jsx as e,jsxs as n}from"react/jsx-runtime";import*as o from"react";import{Field as r}from"@base-ui/react/field";import{Popover as i}from"@base-ui/react/popover";import{MPIcon as t}from"../components/icon/MPIcon.js";import{CloseIcon as l}from"../constants/icons.js";import{accentSlots as s}from"./accent.js";import{MPFieldLabel as a,MPFieldOutline as p,useFloatingLabel as c}from"./FieldOutline.js";import{MPStateLayer as u}from"./StateLayer.js";import{MPSupportingText as m}from"./SupportingText.js";import{MPWidthSizer as d}from"./WidthSizer.js";import{displaySamples as f}from"./date.js";import{CONTROL_ICON as h,hasContent as x,PROSE_TEXT as g}from"./scale.js";import{FADE as b,PORTAL_LAYER as y}from"./surface.js";export function useDisplaySamples(e,n){const r=`${e??""} ${JSON.stringify(n)}`;return o.useMemo(()=>f(e,n),[r])}const j={xs:{padding:"px-2",height:"h-8"},sm:{padding:"px-3",height:"h-10"},md:{padding:"px-4",height:"h-14"},lg:{padding:"px-4",height:"h-16"},xl:{padding:"px-5",height:"h-18"}};export const POPUP_PAD={xs:"p-1.5",sm:"p-2",md:"p-2.5",lg:"p-3",xl:"p-3.5"};export function MPPickerShell({slug:f,size:v="md",color:P="primary",fullWidth:N=!1,label:k,floatingLabel:w=!0,description:C,errorMessage:O,startIcon:M,required:D=!1,disabled:F=!1,readOnly:S=!1,id:z,className:B,style:_,onKeyDown:I,onKeyUp:K,onFocus:R,onBlur:U,onClick:$,onDoubleClick:q,onContextMenu:T,display:A,samples:E,empty:L,clearable:W=!1,onClear:J,open:V,onOpenChange:Z,labels:G,hiddenValues:H,children:Q,triggerRef:X}){const Y=x(O),ee=j[v],ne=o.useId(),oe=z??ne,re=W&&!L&&!(F||S),{shrunk:ie,focusProps:te}=c({floating:w&&x(k),filled:!L,pinned:V||x(M)});return n(r.Root,{disabled:F,invalid:Y,"data-mp-size":v,className:[`mp-${f} group flex-col align-top`,N?"flex w-full":"inline-flex w-fit",B??""].filter(Boolean).join(" "),style:{...s(P),..._},...te,children:[n(i.Root,{open:V,onOpenChange:Z,children:[n("div",{className:"relative w-full",children:[n(i.Trigger,{id:oe,ref:X,disabled:F,nativeButton:!0,onKeyDown:I,onKeyUp:K,onFocus:R,onBlur:U,onClick:$,onDoubleClick:q,onContextMenu:T,className:["relative flex w-full items-center gap-2 select-none","appearance-none border-0 bg-transparent font-[inherit] outline-none",ee.padding,re?"pe-10":"",ee.height,g[v],F?"text-mp-on-surface/38 cursor-default":"text-mp-on-surface "+(S?"cursor-default":"cursor-pointer")].filter(Boolean).join(" "),children:[M?e("span",{className:["flex shrink-0 items-center",F?"text-mp-on-surface/38":"text-mp-on-surface-variant"].join(" "),children:M}):null,n("span",{className:"flex min-w-0 flex-1 flex-col",children:[e("span",{className:["w-full truncate text-start",L&&!F?"text-mp-on-surface-variant":""].filter(Boolean).join(" "),children:L&&!ie?null:A}),e(d,{samples:E??[]})]})]}),re?n("button",{type:"button","aria-label":G.clear,onClick:J,className:["group/clear rounded-mp-full text-mp-on-surface-variant absolute inset-y-0","end-1 my-auto flex size-8 cursor-pointer items-center justify-center","appearance-none border-0 bg-transparent p-0 font-[inherit]","outline-mp-secondary focus-visible:outline-2 focus-visible:outline-offset-1","focus-visible:outline-solid outline-none"].join(" "),children:[e(u,{className:"group-hover/clear:opacity-8 group-focus-visible/clear:opacity-10"}),e(t,{icon:l,size:h[v]})]}):null,e(p,{label:k,required:D,notched:ie}),x(k)?e(a,{size:v,label:k,required:D,htmlFor:oe,shrunk:ie}):null]}),e(i.Portal,{children:e(i.Positioner,{className:y,sideOffset:4,align:"start",children:e(i.Popup,{initialFocus:!1,style:s(P),className:[`mp-${f}__popup rounded-mp-md shadow-mp-2 bg-mp-surface-container`,"text-mp-on-surface outline-none",POPUP_PAD[v],g[v],b].join(" "),children:Q})})})]}),e(m,{description:C,errorMessage:O,className:ee.padding}),H?.map((n,o)=>e("input",{type:"hidden",name:n.name,value:n.value},o))]})}export function MPPickerFooter({children:n}){return e("div",{className:"border-mp-outline-variant flex items-center justify-end gap-1 border-t pt-1.5",children:n})}export function MPPickerDivider(){return e("div",{"aria-hidden":"true",className:"bg-mp-outline-variant w-px self-stretch"})}export const FOOTER_SIZE={xs:"xs",sm:"xs",md:"sm",lg:"sm",xl:"md"};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The wedge that points a floating sheet back at what opened it.
|
|
3
|
+
*
|
|
4
|
+
* Three components draw one — `MPTooltip`, `MPPopover` and `MPHoverCard` — and
|
|
5
|
+
* all three drew it themselves: the same four turn classes, the same viewBox,
|
|
6
|
+
* the same path, the same `aria-hidden`. Only the fill ever differed, and only
|
|
7
|
+
* because a tooltip is drawn on its own ink rather than on a container tone.
|
|
8
|
+
*
|
|
9
|
+
* Three copies of one shape is three chances for one of them to be edited alone,
|
|
10
|
+
* and the failure would be quiet — a wedge one pixel out of line with the sheet
|
|
11
|
+
* above it is not something anybody reports.
|
|
12
|
+
*
|
|
13
|
+
* The positioning stays with the caller. Each of the three has its own `Arrow`
|
|
14
|
+
* part from Base UI, which is what measures the collision and reports the side,
|
|
15
|
+
* and none of them can be swapped for another. So this takes the **className**
|
|
16
|
+
* that goes on that part and the drawing that goes inside it, and the caller
|
|
17
|
+
* spells the two lines that say which part it is.
|
|
18
|
+
*
|
|
19
|
+
* Nothing here is exported from `src/index.ts`. It is the library talking to
|
|
20
|
+
* itself, in the sense `internal/` always means.
|
|
21
|
+
*/
|
|
22
|
+
import * as React from 'react';
|
|
23
|
+
/**
|
|
24
|
+
* Which way the wedge is turned, by the side Base UI says it landed on.
|
|
25
|
+
*
|
|
26
|
+
* Drawn pointing down once and rotated to match, which is a rotation of a glyph
|
|
27
|
+
* — the one allowance the rule against moving a surface makes. The one-pixel
|
|
28
|
+
* overlap on each side is what closes the hairline a fractional position would
|
|
29
|
+
* otherwise leave between the wedge and the sheet it belongs to.
|
|
30
|
+
*/
|
|
31
|
+
export declare const POPUP_ARROW_TURN: string;
|
|
32
|
+
/**
|
|
33
|
+
* The drawing itself, twice as wide as it is tall.
|
|
34
|
+
*
|
|
35
|
+
* `aria-hidden`, because the wedge says nothing a reader has not already been
|
|
36
|
+
* told: the sheet it hangs off is announced by the thing that opened it, and an
|
|
37
|
+
* arrow announced separately would be a second object in the tree that is really
|
|
38
|
+
* a corner of the first.
|
|
39
|
+
*
|
|
40
|
+
* @param size the wedge's width in pixels. It is half that tall.
|
|
41
|
+
* @param fill the surface the sheet is drawn on, as a custom property.
|
|
42
|
+
*/
|
|
43
|
+
export declare function PopupArrow({ size, fill }: {
|
|
44
|
+
size: number;
|
|
45
|
+
fill: string;
|
|
46
|
+
}): React.JSX.Element;
|
|
47
|
+
/**
|
|
48
|
+
* How wide the wedge is at each rung.
|
|
49
|
+
*
|
|
50
|
+
* `MPPopover` and `MPHoverCard` share this one; `MPTooltip` keeps its own, two
|
|
51
|
+
* pixels narrower throughout, because a tooltip is a strip of text rather than a
|
|
52
|
+
* sheet and a wedge sized for a card reads as a spike coming off it.
|
|
53
|
+
*/
|
|
54
|
+
export declare const POPUP_ARROW_SIZE: {
|
|
55
|
+
readonly xs: 8;
|
|
56
|
+
readonly sm: 9;
|
|
57
|
+
readonly md: 10;
|
|
58
|
+
readonly lg: 11;
|
|
59
|
+
readonly xl: 12;
|
|
60
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import{jsx as t}from"react/jsx-runtime";export const POPUP_ARROW_TURN=/*@__PURE__*/["data-[side=top]:bottom-[-1px]","data-[side=bottom]:top-[-1px] data-[side=bottom]:rotate-180","data-[side=left]:right-[-1px] data-[side=left]:-rotate-90","data-[side=right]:left-[-1px] data-[side=right]:rotate-90"].join(" ");export function PopupArrow({size:e,fill:a}){return t("svg",{width:e,height:e/2,viewBox:"0 0 10 5","aria-hidden":"true",className:"block",children:t("path",{d:"M0 0h10L5 5z",fill:a})})}export const POPUP_ARROW_SIZE={xs:8,sm:9,md:10,lg:11,xl:12};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as e}from"react/jsx-runtime";import*as r from"react";import{Field as t}from"@base-ui/react/field";import{META_TEXT as a,hasContent as n}from"./scale.js";export function MPSupportingText({description:o,errorMessage:s,className:i}){const
|
|
2
|
+
import{jsx as e}from"react/jsx-runtime";import*as r from"react";import{Field as t}from"@base-ui/react/field";import{META_TEXT as a,hasContent as n}from"./scale.js";export function MPSupportingText({description:o,errorMessage:s,className:i}){const m=n(s)?"error":n(o)?"description":"none",c=r.useRef(null),p=r.useRef(m);r.useLayoutEffect(()=>{const e=c.current,r=p.current;p.current=m,e&&m!==r&&"none"!==m&&(e.dataset.mpReveal="none"===r?"open":"swap",e.style.animationName="none",e.offsetWidth,e.style.animationName="")},[m]);const l=["mp-supporting-text block min-h-0",a,"data-disabled:text-mp-on-surface/38",i??""].filter(Boolean).join(" ");return n(s)?e("div",{ref:c,className:"mp-supporting-text__reveal",children:e(t.Error,{match:!0,className:`${l} text-mp-error`,children:s})}):n(o)?e("div",{ref:c,className:"mp-supporting-text__reveal",children:e(t.Description,{className:`${l} text-mp-on-surface-variant m-0`,children:o})}):e(t.Error,{className:`${l} text-mp-error`})}
|
package/dist/internal/chart.d.ts
CHANGED
|
@@ -18,16 +18,6 @@ import type { MPChartCategory, MPChartCurve, MPChartDatum, MPChartSeries, MPSize
|
|
|
18
18
|
* second chart.
|
|
19
19
|
*/
|
|
20
20
|
export declare const CHART_SLOTS = 8;
|
|
21
|
-
/**
|
|
22
|
-
* How many series may be told apart when **any two marks can touch** — a
|
|
23
|
-
* scatter, a bubble chart, a heatmap.
|
|
24
|
-
*
|
|
25
|
-
* Three. The eight slots are separable pair-by-pair only that far, and no
|
|
26
|
-
* ordering of eight does better; it is a property of the colour space rather
|
|
27
|
-
* than of this palette. The stylesheet's note on `--_mp-chart-1` has the
|
|
28
|
-
* measurements.
|
|
29
|
-
*/
|
|
30
|
-
export declare const CHART_TOUCHING_SLOTS = 3;
|
|
31
21
|
/**
|
|
32
22
|
* What colour a mark is, in the fixed order the palette is handed out in.
|
|
33
23
|
*
|
package/dist/internal/chart.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{dateTimeFormatter as t,numberFormatter as n}from"./intl.js";export const CHART_SLOTS=8;const o=new Set(["primary","secondary","tertiary","error"]);export function seriesColor(t,n){return n?o.has(n)?`var(--_mp-color-${n})`:n:`var(--_mp-chart-${t%8+1})`}export const COMPACT_FROM=1e4;const r={notation:"compact",maximumFractionDigits:1},e={month:"short",day:"numeric"};export function formatStatistic(t,o,e,a){return Number.isFinite(t)?e?n(o,e).format(t):a&&Math.abs(t)>=1e4?n(o,r).format(t):n(o).format(t):""}export function deltaOf(t,n,o){const r=t-n,e=r>0?1:r<0?-1:0;return{absolute:r,percent:0===n?null:r/Math.abs(n)*100,direction:e,good:0!==e&&1===e==("up"===o)}}function a(t,n){if(0===t.length)return"";if(1===t.length)return`M${t[0].x} ${t[0].y}h0`;const o=`M${t[0].x} ${t[0].y}`;if("smooth"===n)return o+function(t){const n=t.length,o=[];for(let r=0;r<n-1;r+=1){const n=t[r+1].x-t[r].x;o.push(0===n?0:(t[r+1].y-t[r].y)/n)}const r=[o[0]??0];for(let t=1;t<n-1;t+=1){const n=o[t-1],e=o[t];r.push(n*e<=0?0:2*n*e/(n+e))}r.push(o[n-2]??0);const e=[];for(let o=0;o<n-1;o+=1){const n=(t[o+1].x-t[o].x)/3;e.push(`C${t[o].x+n} ${t[o].y+r[o]*n} ${t[o+1].x-n} ${t[o+1].y-r[o+1]*n} ${t[o+1].x} ${t[o+1].y}`)}return e.join("")}(t);const r=[];for(let o=1;o<t.length;o+=1)if("step"===n){const n=(t[o-1].x+t[o].x)/2;r.push(`H${n}V${t[o].y}H${t[o].x}`)}else r.push(`L${t[o].x} ${t[o].y}`);return o+r.join("")}export function linePath(t,n){return function(t){const n=[];let o=[];for(const r of t)null===r?(o.length>0&&n.push(o),o=[]):o.push(r);return o.length>0&&n.push(o),n}(t).map(t=>a(t,n)).join("")}export function bandPath(t,n,o){const r=[];let e=[],i=[];const u=()=>{e.length>0&&r.push(`${a(e,o)}${a([...i].reverse(),o).replace(/^M/,"L")}Z`),e=[],i=[]};return t.forEach((t,o)=>{const r=n[o];null!==t&&null!=r?(e.push(t),i.push(r)):u()}),u(),r.join("")}export function areaPath(t,n,o){return bandPath(t,t.map(t=>null===t?null:{x:t.x,y:n}),o)}export function barPath(t,n,o,r,e,a){const i=Math.abs(o),u=Math.abs(r);if(0===i||0===u)return"";const l=Math.max(0,Math.min(e,i/2,u/2)),c="both"===a,s={tl:c||"top"===a||"left"===a?l:0,tr:c||"top"===a||"right"===a?l:0,br:c||"bottom"===a||"right"===a?l:0,bl:c||"bottom"===a||"left"===a?l:0},x=(t,n,o)=>t>0?`a${t} ${t} 0 0 1 ${n} ${o}`:"";return`M${t+s.tl} ${n}h`+(i-s.tl-s.tr)+x(s.tr,s.tr,s.tr)+"v"+(u-s.tr-s.br)+x(s.br,-s.br,s.br)+"h"+-(i-s.bl-s.br)+x(s.bl,-s.bl,-s.bl)+"v"+-(u-s.tl-s.bl)+x(s.tl,s.tl,-s.tl)+"Z"}export function extentOf(t,n,o){const r=t.filter(t=>null!==t&&Number.isFinite(t)),e=n??(r.length>0?Math.min(...r):0),a=o??(r.length>0?Math.max(...r):0);return e===a?{min:e-.5,max:a+.5}:{min:e,max:a}}export function seriesExtent(t,n){let o=1/0,r=-1/0,e=!1;if(n){const n=t.reduce((t,n)=>Math.max(t,n.length),0);for(let a=0;a<n;a+=1){let n=0,i=0;for(const o of t){const t=o[a]?.value;null!=t&&(e=!0,t>=0?n+=t:i+=t)}o=Math.min(o,i),r=Math.max(r,n)}}else for(const n of t)for(const{value:t}of n)null!==t&&(e=!0,o=Math.min(o,t),r=Math.max(r,t));return e?{min:o,max:r}:null}function i(t){const n=10**Math.floor(Math.log10(t)),o=t/n;return o<=1?n:o<=2?2*n:o<=5?5*n:10*n}export function valueScale(t,n={}){const{tickCount:o=5,includeZero:r=!0}=n;let e=n.min??t?.min??0,a=n.max??t?.max??1;if(r&&void 0===n.min&&(e=Math.min(e,0)),r&&void 0===n.max&&(a=Math.max(a,0)),a===e){const t=Math.abs(a)>0?.5*Math.abs(a):1;e-=t,a+=t}const u=void 0!==n.min&&void 0!==n.max?function(t,n){const o=10**Math.floor(Math.log10(t/Math.max(1,n)));let r=i(t/Math.max(1,n)),e=1/0;for(const a of[.1,1,10])for(const i of[1,2,2.5,5]){const u=i*a*o,l=t/u,c=Math.round(l);if(c<1||Math.abs(l-c)>1e-9)continue;const s=Math.abs(c-n);s<e&&(e=s,r=u)}return r}(a-e,o):i((a-e)/Math.max(1,o)),l=void 0!==n.min?e:Math.floor(e/u)*u,c=void 0!==n.max?a:Math.ceil(a/u)*u,s=c-l||1,x=[];for(let t=l;t<=c+1e-9*u;t+=u)x.push(Number(t.toFixed(12)));return{min:l,max:c,ticks:x,fraction:t=>(t-l)/s}}export function bandScale(t,n,o){const r=t>0?n/t:n;return{step:r,band:r*o,centre:t=>r*(t+.5)}}export function textWidth(t,n){let o=0;for(const n of t)o+=/[ᄀ-ᇿ⺀-가-豈-︰-﹏]/.test(n)?1:.6;return o*n}export function truncate(t,n,o){if(n<=0||textWidth(t,o)<=n)return t;const r=n-textWidth("…",o);let e="",a=0;for(const n of t){const t=a+textWidth(n,o);if(t>r)break;a=t,e+=n}return e.length>0?`${e.trimEnd()}…`:"…"}export function tickStride(t,n,o){return t<=1||n<=0?1:Math.max(1,Math.ceil(t/Math.max(1,Math.floor(n/Math.max(1,o)))))}export function showsTick(t,n,o,r){return t%o===0||r&&t===n-1}export function fitsLast(t,n,o,r){const e=(t-1)%n;return e>0&&e*o>=r+8}export function toValue(t){return null==t?{value:null}:"number"==typeof t?{value:Number.isFinite(t)?t:null}:"object"==typeof t&&"y"in t?{value:null!==t.y&&Number.isFinite(t.y)?t.y:null,x:t.x,z:t.z,color:t.color?seriesColor(0,t.color):void 0,label:t.label}:{value:null}}export function toValues(t){return t.map(t=>t.data.map(toValue))}export function toNumber(t){return t instanceof Date?Number.isFinite(t.getTime())?t.getTime():null:"number"==typeof t&&Number.isFinite(t)?t:null}export function categoryCount(t){return t.reduce((t,n)=>Math.max(t,n.data.length),0)}export function categoryAt(t,n,o){if(n&&t<n.length)return n[t];for(const n of o){const o=n[t]?.x;if(void 0!==o)return o}return t}export function formatCategory(o,r){return o instanceof Date?t(r,e).format(o):"number"==typeof o?n(r).format(o):o}export const PLOT_HEIGHT={xs:120,sm:160,md:220,lg:280,xl:360};export const CHART_FONT_SIZE={xs:10,sm:11,md:12,lg:13,xl:14};export const LINE_WIDTH={xs:1.5,sm:1.75,md:2,lg:2.5,xl:3};export const MARKER_RADIUS={xs:3,sm:3.5,md:4,lg:4.5,xl:5};export const MARK_GAP=2;export const BAR_RADIUS=4;export const BAR_MAX_THICKNESS={xs:24,sm:32,md:40,lg:48,xl:56};export const BAR_BAND_RATIO=.72;export function polarPoint(t,n,o,r){return{x:t+o*Math.sin(r),y:n-o*Math.cos(r)}}export function arcPath(t,n,o,r,e,a){const i=a-e;if(Math.abs(i)<1e-9||o<=0)return"";const u=Math.abs(i)>=2*Math.PI-1e-9,l=u?e+2*Math.PI*Math.sign(i||1):a,c=e+(l-e)/2,s=Math.abs(l-e)>Math.PI?1:0,x=l>e?1:0,h=x?0:1,$=polarPoint(t,n,o,e),f=polarPoint(t,n,o,c),m=polarPoint(t,n,o,l),p=u?`A${o} ${o} 0 0 ${x} ${f.x} ${f.y}A${o} ${o} 0 0 ${x} ${m.x} ${m.y}`:`A${o} ${o} 0 ${s} ${x} ${m.x} ${m.y}`;if(r<=0)return u?`M${$.x} ${$.y}${p}Z`:`M${t} ${n}L${$.x} ${$.y}${p}Z`;const M=polarPoint(t,n,r,l),b=polarPoint(t,n,r,c),d=polarPoint(t,n,r,e),y=u?`A${r} ${r} 0 0 ${h} ${b.x} ${b.y}A${r} ${r} 0 0 ${h} ${d.x} ${d.y}`:`A${r} ${r} 0 ${s} ${h} ${d.x} ${d.y}`;return`M${$.x} ${$.y}${p}L${M.x} ${M.y}${y}Z`}export function categoryExtent(t,n){let o=1/0,r=-1/0,e=!1;return t.forEach(t=>{t.forEach((t,a)=>{if(null===t.value)return;const i=toNumber(t.x??n?.[a]??a);null!==i&&(e=!0,o=Math.min(o,i),r=Math.max(r,i))})}),e?{min:o,max:r}:null}export const MARK_SHAPES=["circle","square","triangle","diamond","cross"];const u={circle:1,square:.886,triangle:1.35,diamond:1.25,cross:1.1};export function markPath(t,n,o,r){const e=r*u[t];switch(t){case"square":return`M${n-e} ${o-e}h${2*e}v${2*e}h${2*-e}Z`;case"triangle":return`M${n} ${o-e}L${n+.866*e} ${o+.5*e}L${n-.866*e} ${o+.5*e}Z`;case"diamond":return`M${n} ${o-e}L${n+e} ${o}L${n} ${o+e}L${n-e} ${o}Z`;case"cross":return`M${n-e} ${o-e}L${n+e} ${o+e}M${n+e} ${o-e}L${n-e} ${o+e}`;default:return`M${n-e} ${o}a${e} ${e} 0 1 0 ${2*e} 0a${e} ${e} 0 1 0 ${2*-e} 0Z`}}export function pointX(t,n,o){return toNumber(t.x??o?.[n]??n)}export function bubbleRadius(t,n,o,r){return n<=0||t<=0?r:r+(o-r)*Math.sqrt(Math.min(1,t/n))}export const RAMP_STEPS=5;export function rampStep(t){return Number.isFinite(t)?Math.min(4,Math.max(0,Math.floor(5*t))):0}export function rampFill(t){return`var(--_mp-chart-scale-${Math.min(5,Math.max(1,t+1))})`}export function rampInk(t){return t>=3?"var(--_mp-color-surface)":"var(--_mp-color-on-surface)"}
|
|
@@ -4,15 +4,6 @@ export type MPColorScheme = 'light' | 'dark' | 'system';
|
|
|
4
4
|
export type MPResolvedColorScheme = 'light' | 'dark';
|
|
5
5
|
export declare const SCHEME_ATTRIBUTE = "data-mp-scheme";
|
|
6
6
|
export declare const DEFAULT_STORAGE_KEY = "mp-color-scheme";
|
|
7
|
-
/**
|
|
8
|
-
* Puts the choice on the document element, or takes it off.
|
|
9
|
-
*
|
|
10
|
-
* `'system'` **removes** the attribute rather than writing it, which is the
|
|
11
|
-
* whole of how the media query gets its say back: the dark block is reached
|
|
12
|
-
* either by `prefers-color-scheme` on a root that is not forced light, or by the
|
|
13
|
-
* attribute. An attribute spelling out `system` would match neither.
|
|
14
|
-
*/
|
|
15
|
-
export declare function applyScheme(scheme: MPColorScheme): void;
|
|
16
7
|
export declare function setScheme(storageKey: string, scheme: MPColorScheme): void;
|
|
17
8
|
export declare function useChosenScheme(storageKey: string): MPColorScheme;
|
|
18
9
|
/**
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import*as e from"react";export const SCHEME_ATTRIBUTE="data-mp-scheme";export const DEFAULT_STORAGE_KEY="mp-color-scheme";const t="(prefers-color-scheme: dark)";function n(e){return"light"===e||"dark"===e||"system"===e}let o;const r=new Set;function c(){for(const e of r)e()}export function
|
|
2
|
+
import*as e from"react";export const SCHEME_ATTRIBUTE="data-mp-scheme";export const DEFAULT_STORAGE_KEY="mp-color-scheme";const t="(prefers-color-scheme: dark)";function n(e){return"light"===e||"dark"===e||"system"===e}let o;const r=new Set;function c(){for(const e of r)e()}export function setScheme(e,t){o=t,function(e,t){try{"system"===t?localStorage.removeItem(e):localStorage.setItem(e,t)}catch{}}(e,t),function(e){if("undefined"==typeof document)return;const t=document.documentElement;"system"===e?t.removeAttribute("data-mp-scheme"):t.setAttribute("data-mp-scheme",e)}(t),c()}function s(e){return r.add(e),()=>{r.delete(e)}}function u(e){return o??=function(){if("undefined"==typeof document)return;const e=document.documentElement.getAttribute("data-mp-scheme");return n(e)&&"system"!==e?e:void 0}()??function(e){try{if("undefined"==typeof localStorage)return"system";const t=localStorage.getItem(e);return n(t)?t:"system"}catch{return"system"}}(e),o}export function useChosenScheme(t){const n=e.useCallback(()=>u(t),[t]);return e.useSyncExternalStore(s,n,()=>"system")}function m(e){if("undefined"==typeof window||!window.matchMedia)return()=>{};const n=window.matchMedia(t);return n.addEventListener("change",e),()=>n.removeEventListener("change",e)}function i(){return"undefined"!=typeof window&&window.matchMedia?.(t).matches?"dark":"light"}export function useSystemScheme(){return e.useSyncExternalStore(m,i,()=>"light")}export function resetScheme(){o=void 0,c()}
|
|
@@ -120,7 +120,8 @@ export declare function searchText(value: unknown): string;
|
|
|
120
120
|
/** Every string a row can be found by, folded once and joined into one haystack. */
|
|
121
121
|
export declare function searchHaystack(values: readonly unknown[]): string;
|
|
122
122
|
/**
|
|
123
|
-
* One field, quoted only when it has to be
|
|
123
|
+
* One field, quoted only when it has to be, and defused when a spreadsheet would
|
|
124
|
+
* otherwise run it.
|
|
124
125
|
*
|
|
125
126
|
* The escaping is the whole job here and getting it wrong is silent: a comma
|
|
126
127
|
* inside a cell shifts every column after it by one, and nobody notices until a
|
|
@@ -128,10 +129,28 @@ export declare function searchHaystack(values: readonly unknown[]): string;
|
|
|
128
129
|
* are in these six lines — a field is quoted if it holds the separator, a quote
|
|
129
130
|
* or a line break, and a quote inside a quoted field is written twice.
|
|
130
131
|
*
|
|
132
|
+
* ## Why a leading apostrophe
|
|
133
|
+
*
|
|
134
|
+
* RFC 4180 has nothing to say about the second problem, which is that a
|
|
135
|
+
* spreadsheet does not read a CSV as data. A cell that begins `=` or `@` or `+`
|
|
136
|
+
* is a **formula**, and `=HYPERLINK("https://…"&A1)` in a table of things other
|
|
137
|
+
* people typed is one click from posting a colleague's row to somebody else's
|
|
138
|
+
* server. It is the reader's own spreadsheet that runs it, so nothing this
|
|
139
|
+
* library does at render time can reach it — the file is where it has to be
|
|
140
|
+
* stopped.
|
|
141
|
+
*
|
|
142
|
+
* An apostrophe in front is the answer Excel, Sheets and LibreOffice all
|
|
143
|
+
* understand: it is their own marker for "the rest of this is text", and all
|
|
144
|
+
* three strip it on the way in. It is not free. A plain CSV parser — `pandas`,
|
|
145
|
+
* a `csv` module, a database loader — has no such rule and will see the
|
|
146
|
+
* apostrophe as part of the value, which is why `escapeFormulas` exists: a file
|
|
147
|
+
* going to a machine rather than to a person is a file nobody is going to open
|
|
148
|
+
* in a spreadsheet, and it should go out byte for byte.
|
|
149
|
+
*
|
|
131
150
|
* `null` and `undefined` are empty rather than the words "null" and "undefined",
|
|
132
151
|
* which is what `String()` would put in the cell.
|
|
133
152
|
*/
|
|
134
|
-
export declare function csvField(value: unknown, separator: string): string;
|
|
153
|
+
export declare function csvField(value: unknown, separator: string, escapeFormulas?: boolean): string;
|
|
135
154
|
export interface MPCsvOptions {
|
|
136
155
|
/** What goes between fields. `;` for the locales whose spreadsheets expect it. */
|
|
137
156
|
separator?: string;
|
|
@@ -143,6 +162,20 @@ export interface MPCsvOptions {
|
|
|
143
162
|
* mojibake. Every other reader ignores the mark.
|
|
144
163
|
*/
|
|
145
164
|
bom?: boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Puts an apostrophe in front of a cell a spreadsheet would otherwise run as a
|
|
167
|
+
* formula.
|
|
168
|
+
*
|
|
169
|
+
* On by default, because the rows in a table are usually things other people
|
|
170
|
+
* typed and the file is usually going to be opened in a spreadsheet — which is
|
|
171
|
+
* the pair that makes a cell beginning `=` an attack rather than a curiosity.
|
|
172
|
+
* A number keeps its sign either way; `csvField` has the whole argument.
|
|
173
|
+
*
|
|
174
|
+
* Turn it off for a file going to a parser rather than to a person, where the
|
|
175
|
+
* apostrophe would arrive as part of the value.
|
|
176
|
+
* @default true
|
|
177
|
+
*/
|
|
178
|
+
escapeFormulas?: boolean;
|
|
146
179
|
}
|
|
147
180
|
/** Rows of already-stringable values, as one CSV document. */
|
|
148
181
|
export declare function toCsv(rows: readonly (readonly unknown[])[], options?: MPCsvOptions): string;
|