@oprt/react 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +105 -2
- package/dist/ActionStatus/ActionStatus.js +104 -0
- package/dist/ActionStatus/ActionStatus.manifest.js +64 -0
- package/dist/ActionStatus/index.js +7 -0
- package/dist/Alert/Alert.js +86 -0
- package/dist/Alert/Alert.manifest.js +36 -0
- package/dist/Alert/index.js +7 -0
- package/dist/AppShell/AppShell.js +103 -0
- package/dist/AppShell/AppShell.manifest.js +66 -0
- package/dist/AppShell/index.js +9 -0
- package/dist/AttachmentPreview/AttachmentPreview.js +145 -0
- package/dist/AttachmentPreview/AttachmentPreview.manifest.js +42 -0
- package/dist/AttachmentPreview/index.js +9 -0
- package/dist/Avatar/Avatar.js +87 -0
- package/dist/Avatar/Avatar.manifest.js +25 -0
- package/dist/Avatar/index.js +7 -0
- package/dist/Badge/Badge.js +124 -0
- package/dist/Badge/Badge.manifest.js +41 -0
- package/dist/Badge/index.js +7 -0
- package/dist/Breadcrumb/Breadcrumb.js +64 -0
- package/dist/Breadcrumb/Breadcrumb.manifest.js +28 -0
- package/dist/Breadcrumb/index.js +7 -0
- package/dist/BulkActionBar/BulkActionBar.js +145 -0
- package/dist/BulkActionBar/BulkActionBar.manifest.js +46 -0
- package/dist/BulkActionBar/index.js +9 -0
- package/dist/BulkActionBar/selection.js +44 -0
- package/dist/BulkResults/BulkResults.js +269 -0
- package/dist/BulkResults/BulkResults.manifest.js +45 -0
- package/dist/BulkResults/index.js +7 -0
- package/dist/Button/Button.js +170 -0
- package/dist/Button/Button.manifest.js +36 -0
- package/dist/Button/index.js +7 -0
- package/dist/ButtonGroup/ButtonGroup.js +60 -0
- package/dist/ButtonGroup/ButtonGroup.manifest.js +22 -0
- package/dist/ButtonGroup/index.js +7 -0
- package/dist/Calendar/Calendar.js +106 -0
- package/dist/Calendar/Calendar.manifest.js +32 -0
- package/dist/Calendar/index.js +7 -0
- package/dist/Card/Card.js +70 -0
- package/dist/Card/Card.manifest.js +57 -0
- package/dist/Card/index.js +16 -0
- package/dist/Chart/Chart.js +1200 -0
- package/dist/Chart/Chart.manifest.js +110 -0
- package/dist/Chart/ChartControls.js +190 -0
- package/dist/Chart/geometry.js +217 -0
- package/dist/Chart/index.js +9 -0
- package/dist/Checkbox/Checkbox.js +166 -0
- package/dist/Checkbox/Checkbox.manifest.js +38 -0
- package/dist/Checkbox/index.js +7 -0
- package/dist/Collapsible/Collapsible.js +177 -0
- package/dist/Collapsible/Collapsible.manifest.js +54 -0
- package/dist/Collapsible/index.js +12 -0
- package/dist/CollectionState/CollectionState.js +68 -0
- package/dist/CollectionState/CollectionState.manifest.js +44 -0
- package/dist/CollectionState/index.js +7 -0
- package/dist/ComboBox/ComboBox.js +221 -0
- package/dist/ComboBox/ComboBox.manifest.js +87 -0
- package/dist/ComboBox/index.js +7 -0
- package/dist/CommandPalette/CommandPalette.js +276 -0
- package/dist/CommandPalette/CommandPalette.manifest.js +24 -0
- package/dist/CommandPalette/index.js +7 -0
- package/dist/ConfirmDialog/ConfirmDialog.js +84 -0
- package/dist/ConfirmDialog/ConfirmDialog.manifest.js +32 -0
- package/dist/ConfirmDialog/index.js +7 -0
- package/dist/ContextMenu/ContextMenu.js +192 -0
- package/dist/ContextMenu/ContextMenu.manifest.js +41 -0
- package/dist/ContextMenu/index.js +7 -0
- package/dist/CoordinateInput/CoordinateInput.js +141 -0
- package/dist/CoordinateInput/CoordinateInput.manifest.js +36 -0
- package/dist/CoordinateInput/index.js +9 -0
- package/dist/CopyButton/CopyButton.js +110 -0
- package/dist/CopyButton/CopyButton.manifest.js +35 -0
- package/dist/CopyButton/index.js +7 -0
- package/dist/DataGrid/DataGrid.js +459 -0
- package/dist/DataGrid/DataGrid.manifest.js +135 -0
- package/dist/DataGrid/PageControls.js +41 -0
- package/dist/DataGrid/index.js +9 -0
- package/dist/DataTable/DataTable.js +375 -0
- package/dist/DataTable/DataTable.manifest.js +86 -0
- package/dist/DataTable/index.js +9 -0
- package/dist/DataTable/sort.js +45 -0
- package/dist/DataTable/useScrollsSideways.js +61 -0
- package/dist/DataTable/useTableWindow.js +185 -0
- package/dist/DatePicker/DatePicker.js +187 -0
- package/dist/DatePicker/DatePicker.manifest.js +40 -0
- package/dist/DatePicker/index.js +7 -0
- package/dist/DateRangePicker/DateRangePicker.js +156 -0
- package/dist/DateRangePicker/DateRangePicker.manifest.js +41 -0
- package/dist/DateRangePicker/index.js +7 -0
- package/dist/DateTimePicker/DateTimePicker.js +213 -0
- package/dist/DateTimePicker/DateTimePicker.manifest.js +44 -0
- package/dist/DateTimePicker/index.js +7 -0
- package/dist/DescriptionList/DescriptionList.js +93 -0
- package/dist/DescriptionList/DescriptionList.manifest.js +40 -0
- package/dist/DescriptionList/index.js +9 -0
- package/dist/Dialog/Dialog.js +214 -0
- package/dist/Dialog/Dialog.manifest.js +31 -0
- package/dist/Dialog/index.js +7 -0
- package/dist/Divider/Divider.js +64 -0
- package/dist/Divider/Divider.manifest.js +21 -0
- package/dist/Divider/index.js +7 -0
- package/dist/DropdownMenu/DropdownMenu.js +170 -0
- package/dist/DropdownMenu/DropdownMenu.manifest.js +82 -0
- package/dist/DropdownMenu/index.js +16 -0
- package/dist/EntityPreview/EntityPreview.js +82 -0
- package/dist/EntityPreview/EntityPreview.manifest.js +43 -0
- package/dist/EntityPreview/index.js +7 -0
- package/dist/EventTimeline/EventTimeline.js +249 -0
- package/dist/EventTimeline/EventTimeline.manifest.js +57 -0
- package/dist/EventTimeline/index.js +7 -0
- package/dist/Field/Field.js +81 -0
- package/dist/Field/Field.manifest.js +32 -0
- package/dist/Field/index.js +9 -0
- package/dist/FileUpload/FileUpload.js +215 -0
- package/dist/FileUpload/FileUpload.manifest.js +48 -0
- package/dist/FileUpload/index.js +7 -0
- package/dist/FilterBar/FilterBar.js +173 -0
- package/dist/FilterBar/FilterBar.manifest.js +49 -0
- package/dist/FilterBar/index.js +7 -0
- package/dist/FormErrorSummary/FormErrorSummary.js +70 -0
- package/dist/FormErrorSummary/FormErrorSummary.manifest.js +29 -0
- package/dist/FormErrorSummary/index.js +9 -0
- package/dist/FormSection/FormSection.js +51 -0
- package/dist/FormSection/FormSection.manifest.js +30 -0
- package/dist/FormSection/index.js +7 -0
- package/dist/InlineEdit/InlineEdit.js +261 -0
- package/dist/InlineEdit/InlineEdit.manifest.js +40 -0
- package/dist/InlineEdit/index.js +7 -0
- package/dist/Input/Input.js +126 -0
- package/dist/Input/Input.manifest.js +49 -0
- package/dist/Input/index.js +7 -0
- package/dist/Inspector/Inspector.js +63 -0
- package/dist/Inspector/Inspector.manifest.js +35 -0
- package/dist/Inspector/index.js +7 -0
- package/dist/JobStatus/JobStatus.js +118 -0
- package/dist/JobStatus/JobStatus.manifest.js +53 -0
- package/dist/JobStatus/index.js +7 -0
- package/dist/LayerControl/LayerControl.js +199 -0
- package/dist/LayerControl/LayerControl.manifest.js +34 -0
- package/dist/LayerControl/index.js +7 -0
- package/dist/Link/Link.js +83 -0
- package/dist/Link/Link.manifest.js +37 -0
- package/dist/Link/index.js +7 -0
- package/dist/MapControls/MapControls.js +122 -0
- package/dist/MapControls/MapControls.manifest.js +31 -0
- package/dist/MapControls/index.js +7 -0
- package/dist/MapLegend/MapLegend.js +89 -0
- package/dist/MapLegend/MapLegend.manifest.js +29 -0
- package/dist/MapLegend/index.js +7 -0
- package/dist/MapScale/MapScale.js +96 -0
- package/dist/MapScale/MapScale.manifest.js +31 -0
- package/dist/MapScale/index.js +7 -0
- package/dist/MediaFrame/MediaFrame.js +113 -0
- package/dist/MediaFrame/MediaFrame.manifest.js +57 -0
- package/dist/MediaFrame/index.js +7 -0
- package/dist/MultiSelect/MultiSelect.js +113 -0
- package/dist/MultiSelect/MultiSelect.manifest.js +51 -0
- package/dist/MultiSelect/index.js +7 -0
- package/dist/NumberInput/NumberInput.js +210 -0
- package/dist/NumberInput/NumberInput.manifest.js +56 -0
- package/dist/NumberInput/index.js +7 -0
- package/dist/OperationalStatus/OperationalStatus.js +89 -0
- package/dist/OperationalStatus/OperationalStatus.manifest.js +39 -0
- package/dist/OperationalStatus/index.js +9 -0
- package/dist/PlaybackControls/PlaybackControls.js +289 -0
- package/dist/PlaybackControls/PlaybackControls.manifest.js +85 -0
- package/dist/PlaybackControls/index.js +7 -0
- package/dist/Popover/Popover.js +302 -0
- package/dist/Popover/Popover.manifest.js +50 -0
- package/dist/Popover/index.js +7 -0
- package/dist/Progress/Progress.js +132 -0
- package/dist/Progress/Progress.manifest.js +30 -0
- package/dist/Progress/index.js +7 -0
- package/dist/PropertyFilter/PropertyFilter.js +306 -0
- package/dist/PropertyFilter/PropertyFilter.manifest.js +32 -0
- package/dist/PropertyFilter/index.js +11 -0
- package/dist/PropertyFilter/tokenError.js +17 -0
- package/dist/RadioGroup/RadioGroup.js +143 -0
- package/dist/RadioGroup/RadioGroup.manifest.js +44 -0
- package/dist/RadioGroup/index.js +9 -0
- package/dist/Select/Select.js +219 -0
- package/dist/Select/Select.manifest.js +77 -0
- package/dist/Select/index.js +9 -0
- package/dist/Sidebar/Sidebar.js +146 -0
- package/dist/Sidebar/Sidebar.manifest.js +72 -0
- package/dist/Sidebar/index.js +18 -0
- package/dist/Skeleton/Skeleton.js +76 -0
- package/dist/Skeleton/Skeleton.manifest.js +30 -0
- package/dist/Skeleton/index.js +7 -0
- package/dist/Slider/Slider.js +246 -0
- package/dist/Slider/Slider.manifest.js +56 -0
- package/dist/Slider/index.js +7 -0
- package/dist/Sparkline/Sparkline.js +135 -0
- package/dist/Sparkline/Sparkline.manifest.js +37 -0
- package/dist/Sparkline/index.js +7 -0
- package/dist/SplitPane/SplitPane.js +316 -0
- package/dist/SplitPane/SplitPane.manifest.js +79 -0
- package/dist/SplitPane/index.js +7 -0
- package/dist/StatCard/StatCard.js +163 -0
- package/dist/StatCard/StatCard.manifest.js +45 -0
- package/dist/StatCard/index.js +7 -0
- package/dist/Tabs/Tabs.js +181 -0
- package/dist/Tabs/Tabs.manifest.js +72 -0
- package/dist/Tabs/index.js +16 -0
- package/dist/Tabs/useTabsIndicator.js +71 -0
- package/dist/Tabs/useTabsScroll.js +123 -0
- package/dist/TagGroup/TagGroup.js +142 -0
- package/dist/TagGroup/TagGroup.manifest.js +35 -0
- package/dist/TagGroup/index.js +7 -0
- package/dist/Textarea/Textarea.js +68 -0
- package/dist/Textarea/Textarea.manifest.js +25 -0
- package/dist/Textarea/index.js +7 -0
- package/dist/TimeField/TimeField.js +118 -0
- package/dist/TimeField/TimeField.manifest.js +42 -0
- package/dist/TimeField/index.js +7 -0
- package/dist/TimeRange/TimeRange.js +184 -0
- package/dist/TimeRange/TimeRange.manifest.js +48 -0
- package/dist/TimeRange/index.js +9 -0
- package/dist/Toast/Toast.js +188 -0
- package/dist/Toast/Toast.manifest.js +77 -0
- package/dist/Toast/index.js +9 -0
- package/dist/Toggle/Toggle.js +154 -0
- package/dist/Toggle/Toggle.manifest.js +54 -0
- package/dist/Toggle/index.js +7 -0
- package/dist/Toolbar/Toolbar.js +86 -0
- package/dist/Toolbar/Toolbar.manifest.js +70 -0
- package/dist/Toolbar/index.js +12 -0
- package/dist/Tooltip/Tooltip.js +122 -0
- package/dist/Tooltip/Tooltip.manifest.js +27 -0
- package/dist/Tooltip/index.js +7 -0
- package/dist/TreeView/TreeView.js +129 -0
- package/dist/TreeView/TreeView.manifest.js +56 -0
- package/dist/TreeView/index.js +7 -0
- package/dist/UploadQueue/UploadQueue.js +296 -0
- package/dist/UploadQueue/UploadQueue.manifest.js +34 -0
- package/dist/UploadQueue/index.js +7 -0
- package/dist/_internal/MotionPopover.js +113 -0
- package/dist/_internal/aria.js +40 -0
- package/dist/_internal/bytes.js +18 -0
- package/dist/_internal/controlStyles.js +26 -0
- package/dist/_internal/date.js +179 -0
- package/dist/_internal/devValidate.js +51 -0
- package/dist/_internal/fieldIds.js +50 -0
- package/dist/_internal/hydration.js +74 -0
- package/dist/_internal/manifest-entry.js +0 -0
- package/dist/_internal/mergeRefs.js +68 -0
- package/dist/_internal/motion.js +138 -0
- package/dist/_internal/navigationLandmark.js +13 -0
- package/dist/_internal/numberText.js +176 -0
- package/dist/_internal/overlay.js +53 -0
- package/dist/_internal/segmentField.js +125 -0
- package/dist/_internal/suggestions.js +20 -0
- package/dist/_internal/timestamp.js +25 -0
- package/dist/_internal/unavailable.js +13 -0
- package/dist/_internal/useActionFocus.js +27 -0
- package/dist/_internal/useElementWidth.js +37 -0
- package/dist/_internal/useIsMounted.js +18 -0
- package/dist/_internal/useIsomorphicLayoutEffect.js +8 -0
- package/dist/_internal/useRestoreFocusOnRemoval.js +57 -0
- package/dist/index.cjs +17811 -0
- package/dist/index.d.cts +2330 -0
- package/dist/index.d.ts +2330 -0
- package/dist/index.js +407 -0
- package/dist/version.js +8 -0
- package/package.json +80 -3
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/_internal/MotionPopover.tsx
|
|
4
|
+
import {
|
|
5
|
+
Popover,
|
|
6
|
+
PopoverContext,
|
|
7
|
+
useSlottedContext
|
|
8
|
+
} from "react-aria-components";
|
|
9
|
+
import { useLayoutEffect, useEffect, useRef } from "react";
|
|
10
|
+
import clsx from "clsx";
|
|
11
|
+
import { useMergedRefs } from "./mergeRefs.js";
|
|
12
|
+
import { jsx } from "react/jsx-runtime";
|
|
13
|
+
function canTakeFocus(element) {
|
|
14
|
+
return !!element && element.isConnected && !element.matches(":disabled");
|
|
15
|
+
}
|
|
16
|
+
function PopoverSurface({
|
|
17
|
+
domProps,
|
|
18
|
+
isExiting,
|
|
19
|
+
triggerRef,
|
|
20
|
+
returnFocusRef,
|
|
21
|
+
trigger,
|
|
22
|
+
placement,
|
|
23
|
+
focusManagement
|
|
24
|
+
}) {
|
|
25
|
+
const surface = useRef(null);
|
|
26
|
+
const surfaceRef = useMergedRefs(
|
|
27
|
+
surface,
|
|
28
|
+
// RAC hands over a callback or an object ref; a legacy string ref is not one it uses.
|
|
29
|
+
domProps.ref
|
|
30
|
+
);
|
|
31
|
+
const wasExiting = useRef(isExiting);
|
|
32
|
+
const restoreFocus = useRef(false);
|
|
33
|
+
const previousPlacement = useRef(placement);
|
|
34
|
+
useLayoutEffect(() => {
|
|
35
|
+
const node = surface.current;
|
|
36
|
+
if (!node) return;
|
|
37
|
+
if (previousPlacement.current && previousPlacement.current !== placement) {
|
|
38
|
+
node.setAttribute("data-oprt-repositioned", "");
|
|
39
|
+
}
|
|
40
|
+
previousPlacement.current = placement;
|
|
41
|
+
if (!isExiting) {
|
|
42
|
+
node.removeAttribute("inert");
|
|
43
|
+
node.removeAttribute("aria-hidden");
|
|
44
|
+
if (wasExiting.current) node.removeAttribute("data-oprt-repositioned");
|
|
45
|
+
}
|
|
46
|
+
if (isExiting && !wasExiting.current)
|
|
47
|
+
restoreFocus.current = node.contains(document.activeElement);
|
|
48
|
+
if (!isExiting && wasExiting.current && focusManagement === "automatic" && trigger !== "ComboBox" && !node.contains(document.activeElement)) {
|
|
49
|
+
const target = node.querySelector("[data-focused], [role=menu], [role=listbox]");
|
|
50
|
+
target?.focus({ preventScroll: true });
|
|
51
|
+
}
|
|
52
|
+
node.toggleAttribute("inert", isExiting);
|
|
53
|
+
if (isExiting) node.setAttribute("aria-hidden", "true");
|
|
54
|
+
if (!isExiting && focusManagement === "manual" && wasExiting.current) {
|
|
55
|
+
node.querySelector("[data-oprt-popover-dialog]")?.focus({ preventScroll: true });
|
|
56
|
+
}
|
|
57
|
+
wasExiting.current = isExiting;
|
|
58
|
+
}, [isExiting, trigger, triggerRef, placement, focusManagement]);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (focusManagement === "automatic" && isExiting && restoreFocus.current) {
|
|
61
|
+
const active = document.activeElement;
|
|
62
|
+
if (active === document.body || surface.current?.contains(active)) {
|
|
63
|
+
const opener = returnFocusRef?.current;
|
|
64
|
+
const target = canTakeFocus(opener) ? opener : triggerRef?.current;
|
|
65
|
+
target?.focus({ preventScroll: true });
|
|
66
|
+
}
|
|
67
|
+
restoreFocus.current = false;
|
|
68
|
+
}
|
|
69
|
+
}, [isExiting, triggerRef, returnFocusRef, focusManagement]);
|
|
70
|
+
return /* @__PURE__ */ jsx(
|
|
71
|
+
"div",
|
|
72
|
+
{
|
|
73
|
+
...domProps,
|
|
74
|
+
"aria-labelledby": focusManagement === "manual" ? void 0 : domProps["aria-labelledby"],
|
|
75
|
+
ref: surfaceRef
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
function MotionPopover({
|
|
80
|
+
motionState,
|
|
81
|
+
className,
|
|
82
|
+
focusManagement = "automatic",
|
|
83
|
+
returnFocusRef,
|
|
84
|
+
...props
|
|
85
|
+
}) {
|
|
86
|
+
const context = useSlottedContext(PopoverContext);
|
|
87
|
+
const triggerRef = props.triggerRef ?? context?.triggerRef;
|
|
88
|
+
const overlayPolicy = focusManagement === "manual" ? { disableFocusManagement: true } : {};
|
|
89
|
+
return /* @__PURE__ */ jsx(
|
|
90
|
+
Popover,
|
|
91
|
+
{
|
|
92
|
+
...props,
|
|
93
|
+
...overlayPolicy,
|
|
94
|
+
className: clsx("oprt-motion oprt-motion-popover", className),
|
|
95
|
+
...motionState.props,
|
|
96
|
+
render: (domProps, { isExiting, trigger, placement }) => /* @__PURE__ */ jsx(
|
|
97
|
+
PopoverSurface,
|
|
98
|
+
{
|
|
99
|
+
domProps: { ...domProps, ...motionState.props },
|
|
100
|
+
isExiting,
|
|
101
|
+
trigger,
|
|
102
|
+
placement,
|
|
103
|
+
triggerRef,
|
|
104
|
+
returnFocusRef,
|
|
105
|
+
focusManagement
|
|
106
|
+
}
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
export {
|
|
112
|
+
MotionPopover
|
|
113
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/_internal/aria.ts
|
|
4
|
+
import { createElement, useCallback } from "react";
|
|
5
|
+
import { useMergedRefs } from "./mergeRefs.js";
|
|
6
|
+
function definedOnly(props) {
|
|
7
|
+
const out = {};
|
|
8
|
+
for (const [k, v] of Object.entries(props)) if (v !== void 0) out[k] = v;
|
|
9
|
+
return out;
|
|
10
|
+
}
|
|
11
|
+
function useAriaInvalidRef(forwarded, invalid) {
|
|
12
|
+
const sync = useCallback(
|
|
13
|
+
(node) => {
|
|
14
|
+
if (!node) return;
|
|
15
|
+
if (invalid) node.setAttribute("aria-invalid", "true");
|
|
16
|
+
else node.removeAttribute("aria-invalid");
|
|
17
|
+
},
|
|
18
|
+
[invalid]
|
|
19
|
+
);
|
|
20
|
+
return useMergedRefs(sync, forwarded);
|
|
21
|
+
}
|
|
22
|
+
function renderInvalidButton(invalid) {
|
|
23
|
+
return (props) => createElement("button", invalid ? { ...props, "aria-invalid": "true" } : props);
|
|
24
|
+
}
|
|
25
|
+
function switchValidationProps({
|
|
26
|
+
invalid,
|
|
27
|
+
required
|
|
28
|
+
}) {
|
|
29
|
+
return {
|
|
30
|
+
...invalid ? { isInvalid: true } : {},
|
|
31
|
+
...required ? { isRequired: true } : {},
|
|
32
|
+
validationBehavior: "aria"
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
definedOnly,
|
|
37
|
+
renderInvalidButton,
|
|
38
|
+
switchValidationProps,
|
|
39
|
+
useAriaInvalidRef
|
|
40
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/_internal/bytes.tsx
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
function isByteCount(value) {
|
|
4
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
|
|
5
|
+
}
|
|
6
|
+
var NUMBER_UNIT_SPACE = "\xA0";
|
|
7
|
+
function ByteCountLabel({ value }) {
|
|
8
|
+
if (!isByteCount(value)) return /* @__PURE__ */ jsx(Fragment, { children: "Invalid file size." });
|
|
9
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
10
|
+
/* @__PURE__ */ jsx("span", { className: "font-mono tabular-nums", children: value }),
|
|
11
|
+
`${NUMBER_UNIT_SPACE}bytes`
|
|
12
|
+
] });
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
ByteCountLabel,
|
|
16
|
+
NUMBER_UNIT_SPACE,
|
|
17
|
+
isByteCount
|
|
18
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/_internal/controlStyles.ts
|
|
2
|
+
import { FORCED_ACTIVE_ROW, MENU_EMPTY, MENU_ROW, POPOVER_WIDTH } from "./overlay.js";
|
|
3
|
+
var FORCED_NO_RESTING_OUTLINE = "forced-colors:[outline-style:none]";
|
|
4
|
+
var FORCED_FOCUS_OUTLINE = "forced-colors:data-[focus-visible]:outline-solid forced-colors:data-[focus-visible]:outline-2 forced-colors:data-[focus-visible]:outline-offset-2 forced-colors:data-[focus-visible]:outline-[color:CanvasText]";
|
|
5
|
+
var FORCED_FOCUS_WITHIN = "forced-colors:focus-within:outline-solid forced-colors:focus-within:outline-2 forced-colors:focus-within:outline-offset-2 forced-colors:focus-within:outline-[color:CanvasText]";
|
|
6
|
+
var FORCED_CHECKBOX_BOX = "forced-colors:group-data-[focus-visible]/checkbox:outline-solid forced-colors:group-data-[focus-visible]/checkbox:outline-2 forced-colors:group-data-[focus-visible]/checkbox:outline-offset-2 forced-colors:group-data-[focus-visible]/checkbox:outline-[color:CanvasText] forced-colors:group-data-[disabled]/checkbox:border-[color:GrayText] forced-colors:group-data-[disabled]/checkbox:text-[color:GrayText]";
|
|
7
|
+
var FORCED_RADIO = "forced-colors:data-[focus-visible]:[&_.oprt-radio-box]:outline-solid forced-colors:data-[focus-visible]:[&_.oprt-radio-box]:outline-2 forced-colors:data-[focus-visible]:[&_.oprt-radio-box]:outline-offset-2 forced-colors:data-[focus-visible]:[&_.oprt-radio-box]:outline-[color:CanvasText] forced-colors:data-[disabled]:text-[color:GrayText] forced-colors:data-[disabled]:[&_.oprt-radio-box]:border-[color:GrayText] forced-colors:data-[disabled]:[&_.oprt-radio-inner]:text-[color:GrayText]";
|
|
8
|
+
var FORCED_SLIDER_TRACK = "forced-colors:[forced-color-adjust:none] forced-colors:border forced-colors:border-[color:CanvasText] forced-colors:bg-[color:Canvas] forced-colors:data-[disabled]:border-[color:GrayText]";
|
|
9
|
+
var FORCED_SLIDER_FILL = "forced-colors:bg-[color:Highlight] forced-colors:data-[disabled]:bg-[color:GrayText]";
|
|
10
|
+
var FORCED_SLIDER_THUMB = "forced-colors:bg-[color:Canvas] forced-colors:border-[color:CanvasText] forced-colors:group-data-[focus-visible]/slider:outline-solid forced-colors:group-data-[focus-visible]/slider:outline-2 forced-colors:group-data-[focus-visible]/slider:outline-offset-2 forced-colors:group-data-[focus-visible]/slider:outline-[color:CanvasText] forced-colors:group-data-[focus-visible]/slider:border-[color:CanvasText] forced-colors:group-data-[focus-visible]/slider:shadow-none forced-colors:group-data-[invalid]/slider:border-[color:CanvasText] forced-colors:group-data-[disabled]/slider:[&&]:border-[color:GrayText]";
|
|
11
|
+
var LISTBOX_SURFACE = `z-50 min-w-[min(var(--trigger-width),calc(100vw-var(--oprt-space-4)))] ${POPOVER_WIDTH} overflow-auto overscroll-contain border border-oprt-accent bg-oprt-surface-1 font-sans shadow-oprt-focus`;
|
|
12
|
+
var LISTBOX_ROW = `${MENU_ROW} cursor-pointer font-sans text-oprt-base font-medium normal-case text-oprt-text outline-hidden data-[focused]:bg-oprt-surface-3 data-[focus-visible]:border-oprt-border-focus data-[focus-visible]:shadow-oprt-focus data-[selected]:text-oprt-accent data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50 ${FORCED_ACTIVE_ROW}`;
|
|
13
|
+
var LISTBOX_EMPTY = MENU_EMPTY;
|
|
14
|
+
export {
|
|
15
|
+
FORCED_CHECKBOX_BOX,
|
|
16
|
+
FORCED_FOCUS_OUTLINE,
|
|
17
|
+
FORCED_FOCUS_WITHIN,
|
|
18
|
+
FORCED_NO_RESTING_OUTLINE,
|
|
19
|
+
FORCED_RADIO,
|
|
20
|
+
FORCED_SLIDER_FILL,
|
|
21
|
+
FORCED_SLIDER_THUMB,
|
|
22
|
+
FORCED_SLIDER_TRACK,
|
|
23
|
+
LISTBOX_EMPTY,
|
|
24
|
+
LISTBOX_ROW,
|
|
25
|
+
LISTBOX_SURFACE
|
|
26
|
+
};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// src/_internal/date.ts
|
|
2
|
+
import {
|
|
3
|
+
CalendarDate,
|
|
4
|
+
parseDate,
|
|
5
|
+
Time,
|
|
6
|
+
fromAbsolute,
|
|
7
|
+
toCalendarDate,
|
|
8
|
+
toCalendarDateTime,
|
|
9
|
+
toZoned
|
|
10
|
+
} from "@internationalized/date";
|
|
11
|
+
import { isValidTimestamp } from "./timestamp.js";
|
|
12
|
+
function parseTimeOnly(value) {
|
|
13
|
+
if (typeof value !== "string" || !/^(?:[01]\d|2[0-3]):[0-5]\d$/.test(value)) return null;
|
|
14
|
+
const [hour, minute] = value.split(":").map(Number);
|
|
15
|
+
return new Time(hour, minute);
|
|
16
|
+
}
|
|
17
|
+
function formatTimeOnly(value) {
|
|
18
|
+
return `${String(value.hour).padStart(2, "0")}:${String(value.minute).padStart(2, "0")}`;
|
|
19
|
+
}
|
|
20
|
+
function timeConfiguration(value, min, max) {
|
|
21
|
+
const time = parseTimeOnly(value);
|
|
22
|
+
const minimum = min === void 0 ? new Time(0, 0) : parseTimeOnly(min);
|
|
23
|
+
const maximum = max === void 0 ? new Time(23, 59) : parseTimeOnly(max);
|
|
24
|
+
const invalidBounds = !minimum || !maximum || minimum.compare(maximum) > 0;
|
|
25
|
+
const error = invalidBounds ? "Invalid time bounds. Use HH:mm times with the minimum before or equal to the maximum." : value !== null && !time ? "Invalid time. Use HH:mm from 00:00 through 23:59." : time && minimum && time.compare(minimum) < 0 ? `Choose a time at or after ${min}.` : time && maximum && time.compare(maximum) > 0 ? `Choose a time at or before ${max}.` : null;
|
|
26
|
+
return {
|
|
27
|
+
time,
|
|
28
|
+
min: invalidBounds ? new Time(0, 0) : minimum,
|
|
29
|
+
max: invalidBounds ? new Time(23, 59) : maximum,
|
|
30
|
+
invalidBounds,
|
|
31
|
+
error
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function readTimeSegments(segments) {
|
|
35
|
+
const fields = ["hour", "minute"].map(
|
|
36
|
+
(type) => segments.find((segment) => segment.type === type)
|
|
37
|
+
);
|
|
38
|
+
if (fields.every((field) => field?.isPlaceholder))
|
|
39
|
+
return { value: null, empty: true, valid: true };
|
|
40
|
+
if (fields.some((field) => !field || field.isPlaceholder || field.value == null))
|
|
41
|
+
return { value: null, empty: false, valid: false };
|
|
42
|
+
const value = fields.map((field) => String(field.value).padStart(2, "0")).join(":");
|
|
43
|
+
return { value, empty: false, valid: !!parseTimeOnly(value) };
|
|
44
|
+
}
|
|
45
|
+
function validTimeZone(timeZone) {
|
|
46
|
+
if (typeof timeZone !== "string") return false;
|
|
47
|
+
if (!timeZone || timeZone.trim() !== timeZone || /^[+-]/.test(timeZone)) return false;
|
|
48
|
+
try {
|
|
49
|
+
new Intl.DateTimeFormat("en-US", { timeZone }).format(0);
|
|
50
|
+
return true;
|
|
51
|
+
} catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function validInstant(value) {
|
|
56
|
+
return isValidTimestamp(value, { integer: true });
|
|
57
|
+
}
|
|
58
|
+
function resolveWallTime(date, time, timeZone) {
|
|
59
|
+
if (!validTimeZone(timeZone))
|
|
60
|
+
return { status: "invalid", error: "Invalid time zone. Supply an IANA time zone." };
|
|
61
|
+
const day = parseDateOnly(date);
|
|
62
|
+
const clock = parseTimeOnly(time);
|
|
63
|
+
if (!day || !clock) return { status: "invalid", error: "Enter a complete, valid date and time." };
|
|
64
|
+
const wall = toCalendarDateTime(day, clock);
|
|
65
|
+
try {
|
|
66
|
+
const earlier = toZoned(wall, timeZone, "earlier");
|
|
67
|
+
const later = toZoned(wall, timeZone, "later");
|
|
68
|
+
if (toCalendarDateTime(earlier).compare(wall) !== 0 || toCalendarDateTime(later).compare(wall) !== 0) {
|
|
69
|
+
return {
|
|
70
|
+
status: "invalid",
|
|
71
|
+
error: `This time does not exist in ${timeZone} because the clock moves forward. Choose another time.`
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {
|
|
75
|
+
status: "valid",
|
|
76
|
+
earlier: earlier.toDate().getTime(),
|
|
77
|
+
later: later.toDate().getTime()
|
|
78
|
+
};
|
|
79
|
+
} catch {
|
|
80
|
+
return {
|
|
81
|
+
status: "invalid",
|
|
82
|
+
error: "This date and time cannot be resolved in the supplied zone."
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function instantWallTime(value, timeZone) {
|
|
87
|
+
if (value === null) return { date: null, time: null, occurrence: null, error: null };
|
|
88
|
+
if (!validInstant(value))
|
|
89
|
+
return {
|
|
90
|
+
date: null,
|
|
91
|
+
time: null,
|
|
92
|
+
occurrence: null,
|
|
93
|
+
error: "Invalid instant. Supply finite epoch milliseconds."
|
|
94
|
+
};
|
|
95
|
+
if (!validTimeZone(timeZone))
|
|
96
|
+
return {
|
|
97
|
+
date: null,
|
|
98
|
+
time: null,
|
|
99
|
+
occurrence: null,
|
|
100
|
+
error: "Invalid time zone. Supply an IANA time zone."
|
|
101
|
+
};
|
|
102
|
+
try {
|
|
103
|
+
const zoned = fromAbsolute(value, timeZone);
|
|
104
|
+
const date = toCalendarDate(zoned).toString();
|
|
105
|
+
const time = formatTimeOnly(zoned);
|
|
106
|
+
if (zoned.toDate().getTime() !== value || !parseDateOnly(date))
|
|
107
|
+
return {
|
|
108
|
+
date: null,
|
|
109
|
+
time: null,
|
|
110
|
+
occurrence: null,
|
|
111
|
+
error: "The date must use a year from 0001 through 9999."
|
|
112
|
+
};
|
|
113
|
+
const resolved = resolveWallTime(date, time, timeZone);
|
|
114
|
+
let occurrence = null;
|
|
115
|
+
if (resolved.status === "valid" && resolved.earlier !== resolved.later) {
|
|
116
|
+
occurrence = fromAbsolute(resolved.later, timeZone).offset === zoned.offset ? "later" : "earlier";
|
|
117
|
+
}
|
|
118
|
+
return { date, time, occurrence, error: null };
|
|
119
|
+
} catch {
|
|
120
|
+
return {
|
|
121
|
+
date: null,
|
|
122
|
+
time: null,
|
|
123
|
+
occurrence: null,
|
|
124
|
+
error: "Invalid instant for the supplied time zone."
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function parseDateOnly(value) {
|
|
129
|
+
if (typeof value !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return null;
|
|
130
|
+
try {
|
|
131
|
+
const date = parseDate(value);
|
|
132
|
+
return date.year >= 1 && date.year <= 9999 && date.toString() === value ? date : null;
|
|
133
|
+
} catch {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function dateConfiguration(value, min, max) {
|
|
138
|
+
const date = parseDateOnly(value);
|
|
139
|
+
const minimum = min === void 0 ? new CalendarDate(1, 1, 1) : parseDateOnly(min);
|
|
140
|
+
const maximum = max === void 0 ? new CalendarDate(9999, 12, 31) : parseDateOnly(max);
|
|
141
|
+
const invalidBounds = !minimum || !maximum || minimum.compare(maximum) > 0;
|
|
142
|
+
const error = invalidBounds ? "Invalid date bounds. Use YYYY-MM-DD dates with the minimum before or equal to the maximum." : value !== null && !date ? "Invalid date. Use a real Gregorian date in YYYY-MM-DD format." : date && minimum && date.compare(minimum) < 0 ? `Choose a date on or after ${min}.` : date && maximum && date.compare(maximum) > 0 ? `Choose a date on or before ${max}.` : null;
|
|
143
|
+
return {
|
|
144
|
+
date,
|
|
145
|
+
min: invalidBounds ? new CalendarDate(1, 1, 1) : minimum,
|
|
146
|
+
max: invalidBounds ? new CalendarDate(9999, 12, 31) : maximum,
|
|
147
|
+
invalidBounds,
|
|
148
|
+
error
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function dateWithinBounds(date, min, max) {
|
|
152
|
+
return date.compare(min) >= 0 && date.compare(max) <= 0;
|
|
153
|
+
}
|
|
154
|
+
function readDateSegments(segments) {
|
|
155
|
+
const fields = ["year", "month", "day"].map(
|
|
156
|
+
(type) => segments.find((segment) => segment.type === type)
|
|
157
|
+
);
|
|
158
|
+
const empty = fields.every((field) => field?.isPlaceholder);
|
|
159
|
+
if (empty) return { value: null, empty: true, valid: true };
|
|
160
|
+
if (fields.some((field) => !field || field.isPlaceholder || field.value == null)) {
|
|
161
|
+
return { value: null, empty: false, valid: false };
|
|
162
|
+
}
|
|
163
|
+
const value = fields.map((field, index) => String(field.value).padStart(index === 0 ? 4 : 2, "0")).join("-");
|
|
164
|
+
return { value, empty: false, valid: parseDateOnly(value) !== null };
|
|
165
|
+
}
|
|
166
|
+
export {
|
|
167
|
+
dateConfiguration,
|
|
168
|
+
dateWithinBounds,
|
|
169
|
+
formatTimeOnly,
|
|
170
|
+
instantWallTime,
|
|
171
|
+
parseDateOnly,
|
|
172
|
+
parseTimeOnly,
|
|
173
|
+
readDateSegments,
|
|
174
|
+
readTimeSegments,
|
|
175
|
+
resolveWallTime,
|
|
176
|
+
timeConfiguration,
|
|
177
|
+
validInstant,
|
|
178
|
+
validTimeZone
|
|
179
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/_internal/devValidate.ts
|
|
2
|
+
import { SUGGESTION_OVERRIDES } from "./suggestions.js";
|
|
3
|
+
var seen = /* @__PURE__ */ new Set();
|
|
4
|
+
var own = (table, key) => Object.prototype.hasOwnProperty.call(table, key);
|
|
5
|
+
function editorialSuggestion(component, prop, value) {
|
|
6
|
+
if (!own(SUGGESTION_OVERRIDES, component)) return void 0;
|
|
7
|
+
const byProp = SUGGESTION_OVERRIDES[component];
|
|
8
|
+
if (!own(byProp, prop)) return void 0;
|
|
9
|
+
const byValue = byProp[prop];
|
|
10
|
+
return own(byValue, value) ? byValue[value] : void 0;
|
|
11
|
+
}
|
|
12
|
+
function callingComponent() {
|
|
13
|
+
for (const frame of (new Error().stack ?? "").split("\n").slice(1)) {
|
|
14
|
+
if (/\/_internal\/|node_modules\/(?:\.pnpm\/[^/]*\/node_modules\/)?react(?:-dom)?\//.test(frame))
|
|
15
|
+
continue;
|
|
16
|
+
const file = /([^/\\()\s]+?)\.(?:[cm]?[jt]sx?)(?:\?[^:)\s]*)?:\d+:\d+\)?\s*$/.exec(frame)?.[1];
|
|
17
|
+
if (file !== void 0) return /^[A-Z]/.test(file) ? file : void 0;
|
|
18
|
+
}
|
|
19
|
+
return void 0;
|
|
20
|
+
}
|
|
21
|
+
function devValidate(component, manifestProps, received) {
|
|
22
|
+
if (process.env.NODE_ENV === "production") return;
|
|
23
|
+
for (const [prop, value] of Object.entries(received)) {
|
|
24
|
+
if (typeof value !== "string") continue;
|
|
25
|
+
const def = own(manifestProps, prop) ? manifestProps[prop] : void 0;
|
|
26
|
+
if (!def || def.type !== "enum") continue;
|
|
27
|
+
if (def.values.includes(value)) continue;
|
|
28
|
+
const key = `${component}.${prop}.${value}`;
|
|
29
|
+
if (seen.has(key)) continue;
|
|
30
|
+
seen.add(key);
|
|
31
|
+
const suggestion = editorialSuggestion(component, prop, value) ?? `Valid values for \`${prop}\`: ${def.values.join(", ")}` + (def.default !== void 0 ? ` (default: ${def.default}).` : ".");
|
|
32
|
+
console.error(
|
|
33
|
+
JSON.stringify(
|
|
34
|
+
{
|
|
35
|
+
component,
|
|
36
|
+
error: "INVALID_PROP_VALUE",
|
|
37
|
+
prop,
|
|
38
|
+
received: value,
|
|
39
|
+
valid_values: def.values,
|
|
40
|
+
suggestion
|
|
41
|
+
},
|
|
42
|
+
null,
|
|
43
|
+
2
|
|
44
|
+
)
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
callingComponent,
|
|
50
|
+
devValidate
|
|
51
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/_internal/fieldIds.ts
|
|
4
|
+
import { createContext, useContext } from "react";
|
|
5
|
+
import { useHydratedId } from "./hydration.js";
|
|
6
|
+
var FieldContext = createContext(null);
|
|
7
|
+
function joinIds(...ids) {
|
|
8
|
+
const joined = /* @__PURE__ */ new Set();
|
|
9
|
+
for (const id of ids) {
|
|
10
|
+
if (!id) continue;
|
|
11
|
+
for (const token of id.split(/\s+/)) if (token) joined.add(token);
|
|
12
|
+
}
|
|
13
|
+
return joined.size > 0 ? [...joined].join(" ") : void 0;
|
|
14
|
+
}
|
|
15
|
+
function usePartIds(parts, options = {}) {
|
|
16
|
+
const { id, readRendered } = options;
|
|
17
|
+
const generated = useHydratedId(() => id === void 0 ? readRendered?.() : void 0);
|
|
18
|
+
const base = id ?? generated;
|
|
19
|
+
const ids = { base };
|
|
20
|
+
for (const part of parts) ids[part] = `${base}-${part}`;
|
|
21
|
+
return ids;
|
|
22
|
+
}
|
|
23
|
+
function ariaInvalidValue(value) {
|
|
24
|
+
if (value === void 0) return void 0;
|
|
25
|
+
return value === true || value === "true";
|
|
26
|
+
}
|
|
27
|
+
function ariaInvalidToken(value) {
|
|
28
|
+
return typeof value === "string" && value !== "true" && value !== "false" ? value : void 0;
|
|
29
|
+
}
|
|
30
|
+
function useFieldWiring(own, options) {
|
|
31
|
+
const field = useContext(FieldContext);
|
|
32
|
+
const namedByField = options.label === "labelledby" && !own["aria-label"] && !options.ownLabel;
|
|
33
|
+
const invalid = own.invalid ?? ariaInvalidValue(own["aria-invalid"]) ?? field?.invalid ?? false;
|
|
34
|
+
return {
|
|
35
|
+
id: own.id ?? field?.id,
|
|
36
|
+
labelledBy: own["aria-labelledby"] ?? (namedByField ? field?.labelId : void 0),
|
|
37
|
+
describedBy: own["aria-describedby"] ?? field?.describedBy,
|
|
38
|
+
invalid,
|
|
39
|
+
// Its own `invalid` decides first, so a token shows only where `invalid` was not given.
|
|
40
|
+
ariaInvalid: invalid ? true : own.invalid == null ? ariaInvalidToken(own["aria-invalid"]) : void 0,
|
|
41
|
+
required: own.required ?? field?.required ?? false,
|
|
42
|
+
field
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export {
|
|
46
|
+
FieldContext,
|
|
47
|
+
joinIds,
|
|
48
|
+
useFieldWiring,
|
|
49
|
+
usePartIds
|
|
50
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/_internal/hydration.ts
|
|
4
|
+
import { useId, useRef, useState, useSyncExternalStore } from "react";
|
|
5
|
+
import { useIsomorphicLayoutEffect } from "./useIsomorphicLayoutEffect.js";
|
|
6
|
+
function keyForIds(...forwardedIds) {
|
|
7
|
+
return forwardedIds.join(" ");
|
|
8
|
+
}
|
|
9
|
+
var subscribeNoop = () => () => {
|
|
10
|
+
};
|
|
11
|
+
var getClientSnapshot = () => true;
|
|
12
|
+
var getServerSnapshot = () => false;
|
|
13
|
+
var PROBE_ATTRIBUTE = "data-oprt-hydration";
|
|
14
|
+
function markupCarries(probe) {
|
|
15
|
+
for (const element of document.querySelectorAll(`[${PROBE_ATTRIBUTE}]`)) {
|
|
16
|
+
if (element.getAttribute(PROBE_ATTRIBUTE) === probe) return true;
|
|
17
|
+
}
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
var warnedAbout = /* @__PURE__ */ new Set();
|
|
21
|
+
var HOOK_NAME = "useHydrationRoot";
|
|
22
|
+
function callerOfHook() {
|
|
23
|
+
const lines = new Error().stack?.split("\n") ?? [];
|
|
24
|
+
const own = lines.findIndex((line) => line.includes(HOOK_NAME));
|
|
25
|
+
return (lines[own >= 0 ? own + 1 : 3] ?? "an unknown component").trim();
|
|
26
|
+
}
|
|
27
|
+
function warnProbeMissing(origin) {
|
|
28
|
+
const where = origin ?? "an unknown component";
|
|
29
|
+
if (warnedAbout.has(where)) return;
|
|
30
|
+
warnedAbout.add(where);
|
|
31
|
+
console.warn(
|
|
32
|
+
`${HOOK_NAME}: no element in the document carries this root's probeProps, so it remounts after every hydration and a keyboard user loses their place. Spread hydration.probeProps on an element the component renders. Called from ${where}`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
function useHydrationRoot(...forwardedIds) {
|
|
36
|
+
const probe = useId();
|
|
37
|
+
const hydrated = useSyncExternalStore(subscribeNoop, getClientSnapshot, getServerSnapshot);
|
|
38
|
+
const hydratingMount = useRef();
|
|
39
|
+
if (hydratingMount.current === void 0) hydratingMount.current = !hydrated;
|
|
40
|
+
const [disagrees, setDisagrees] = useState(false);
|
|
41
|
+
const clientOnly = useRef(hydrated);
|
|
42
|
+
const origin = useRef();
|
|
43
|
+
if (process.env.NODE_ENV !== "production" && origin.current === void 0) {
|
|
44
|
+
origin.current = callerOfHook();
|
|
45
|
+
}
|
|
46
|
+
useIsomorphicLayoutEffect(() => {
|
|
47
|
+
if (!hydrated || !hydratingMount.current) return;
|
|
48
|
+
hydratingMount.current = false;
|
|
49
|
+
if (!markupCarries(probe)) setDisagrees(true);
|
|
50
|
+
}, [hydrated, probe]);
|
|
51
|
+
useIsomorphicLayoutEffect(() => {
|
|
52
|
+
if (process.env.NODE_ENV === "production" || !clientOnly.current) return;
|
|
53
|
+
if (!markupCarries(probe)) warnProbeMissing(origin.current);
|
|
54
|
+
}, [probe]);
|
|
55
|
+
return {
|
|
56
|
+
key: `${disagrees ? "client" : "server"} ${keyForIds(...forwardedIds)}`,
|
|
57
|
+
probeProps: { [PROBE_ATTRIBUTE]: probe }
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function useHydratedId(readRenderedId) {
|
|
61
|
+
const reactId = useId();
|
|
62
|
+
const [renderedId, setRenderedId] = useState();
|
|
63
|
+
const read = useRef(readRenderedId);
|
|
64
|
+
useIsomorphicLayoutEffect(() => {
|
|
65
|
+
const id = read.current();
|
|
66
|
+
if (id && id !== reactId) setRenderedId(id);
|
|
67
|
+
}, [reactId]);
|
|
68
|
+
return renderedId ?? reactId;
|
|
69
|
+
}
|
|
70
|
+
export {
|
|
71
|
+
keyForIds,
|
|
72
|
+
useHydratedId,
|
|
73
|
+
useHydrationRoot
|
|
74
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/_internal/mergeRefs.ts
|
|
4
|
+
import {
|
|
5
|
+
useMemo,
|
|
6
|
+
useRef,
|
|
7
|
+
version
|
|
8
|
+
} from "react";
|
|
9
|
+
var supportsRefCleanup = Number.parseInt(version, 10) >= 19;
|
|
10
|
+
function setRef(ref, node) {
|
|
11
|
+
if (typeof ref === "function") return ref(node);
|
|
12
|
+
if (ref !== null && typeof ref === "object") ref.current = node;
|
|
13
|
+
}
|
|
14
|
+
function mergeRefs(...refs) {
|
|
15
|
+
return (node) => {
|
|
16
|
+
if (node === null) {
|
|
17
|
+
for (const ref of refs) setRef(ref, null);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const cleanups = refs.map((ref) => {
|
|
21
|
+
const result = setRef(ref, node);
|
|
22
|
+
return typeof result === "function" ? result : null;
|
|
23
|
+
});
|
|
24
|
+
if (!supportsRefCleanup) return;
|
|
25
|
+
return () => {
|
|
26
|
+
refs.forEach((ref, index) => {
|
|
27
|
+
const cleanup = cleanups[index];
|
|
28
|
+
if (cleanup) cleanup();
|
|
29
|
+
else setRef(ref, null);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function useMergedRefs(...refs) {
|
|
35
|
+
return useMemo(() => mergeRefs(...refs), refs);
|
|
36
|
+
}
|
|
37
|
+
function useInputRefObject(setNode) {
|
|
38
|
+
const node = useRef(null);
|
|
39
|
+
const cleanup = useRef(null);
|
|
40
|
+
return useMemo(
|
|
41
|
+
() => ({
|
|
42
|
+
get current() {
|
|
43
|
+
return node.current;
|
|
44
|
+
},
|
|
45
|
+
set current(next) {
|
|
46
|
+
const previous = node.current;
|
|
47
|
+
node.current = next;
|
|
48
|
+
if (previous !== null) {
|
|
49
|
+
const run = cleanup.current;
|
|
50
|
+
cleanup.current = null;
|
|
51
|
+
if (run) run();
|
|
52
|
+
else setNode(null);
|
|
53
|
+
}
|
|
54
|
+
if (next !== null) {
|
|
55
|
+
const result = setNode(next);
|
|
56
|
+
cleanup.current = typeof result === "function" ? result : null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}),
|
|
60
|
+
[setNode]
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
mergeRefs,
|
|
65
|
+
setRef,
|
|
66
|
+
useInputRefObject,
|
|
67
|
+
useMergedRefs
|
|
68
|
+
};
|