merge: integrate range calendar foundation and handoff
This commit is contained in:
@@ -484,3 +484,11 @@ DateField/DateInputGroup 已公开,先读[DATE-02 报告](docs/migrations/DATE
|
||||
## DATE-03 日期迁移恢复(2026-10-24)
|
||||
|
||||
用户在文档任务完成后明确继续集成人负责的组件,DATE-02 暂停记录不再阻止日期接续。Calendar/CalendarYearPicker 的当前范围见 [DATE-03](docs/migrations/DATE-03-calendar.md)。月/周/日共用局部视图和接受值协议,不把受控焦点、选中与可见窗口混为一个值;pageBehavior=single 在多单位视图内也必须移动窗口。原生取消、无可用初始焦点、外部程序聚焦不抢焦点、重复补位日期与多选键盘重复分别回归。YearPicker 测真实覆盖几何/滚动/焦点和关闭拒绝,SSR/类型不能代替浏览器。Root/全部 Props、variants 与独立 YearPicker 部件从包根导出,消费契约须有实际反例。下一步 RangeCalendar → Picker/TimeField,颜色基建后续实施,仍由集成人维护日期状态边界。
|
||||
|
||||
## DATE-04 范围基建与交接(2026-10-25)
|
||||
|
||||
用户要求集成人集中处理复杂交互与架构,常规公开收尾交给其他 AI。先读 [DATE-04](docs/migrations/DATE-04-range-foundation.md);Calendar/RangeCalendar 共用 calendar/view.ts 和同一 Cell 键盘层,范围接受值与草稿锚点分开。不可用障碍、受控焦点、模型拒绝/重试、端点精度/zone、鼠标拖动/取消/清理已由私有夹具验证;尚未公开 RangeCalendar 或补齐正式示例。
|
||||
|
||||
浏览器可以在原生监听器之间执行微任务,document capture 后不能用 queueMicrotask 清掉尚未执行的目标处理器;改用整次派发后且可取消的任务。disabled/outside-month 原生按钮仍可能收到 pointerenter,桥接必须检查真实 Cell 状态;不要只按日期边界判断。样式适配原生按钮拉伸,不能被 playground 的全局 header/font 规则覆盖。
|
||||
|
||||
下一轮其他 AI 按 [DATE-05 提示词](docs/migrations/DATE-05-range-calendar-prompt.md) 同步 main 后新开分支,只消费内核完成公开十部件/六个年份别名、类型、20 例与文档。真实缺口交失败用例给集成人。触屏长按、范围字段/Picker/Time 桥接与颜色共享状态仍由集成人处理,不能从私有夹具或 Calendar 验收推断已完成。
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
"dependencies": {
|
||||
"@heroui-vue/components": "workspace:*",
|
||||
"@heroui-vue/styles": "workspace:*",
|
||||
"vue": "^3.5.44"
|
||||
"vue": "^3.5.44",
|
||||
"@internationalized/date": "3.12.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/vite": "^4.1.0",
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import RangeCalendarFoundationLab from "./RangeCalendarFoundationLab.vue";
|
||||
const rangeFoundation =
|
||||
typeof window !== "undefined" &&
|
||||
new URLSearchParams(window.location.search).has("range-calendar-foundation");
|
||||
import SelectLifecycle from "../../../packages/vue/tests/fixtures/SelectLifecycle.vue";
|
||||
const selectLifecycle =
|
||||
typeof window !== "undefined" &&
|
||||
@@ -31,7 +35,8 @@ function save() {
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<SelectLifecycle v-if="selectLifecycle" />
|
||||
<RangeCalendarFoundationLab v-if="rangeFoundation" />
|
||||
<SelectLifecycle v-else-if="selectLifecycle" />
|
||||
<ScrollTabsLab v-else-if="scrollTabsLab" />
|
||||
<OverlayAnimationLab v-else-if="animationLab" />
|
||||
<OverlayComponentsLab v-else-if="componentsLab" />
|
||||
|
||||
@@ -0,0 +1,146 @@
|
||||
<script setup lang="ts">
|
||||
import { shallowRef } from "vue";
|
||||
import { CalendarDate } from "@internationalized/date";
|
||||
import Range from "../../../packages/vue/tests/fixtures/RangeCalendarFoundation.vue";
|
||||
import {
|
||||
Button,
|
||||
CalendarGrid,
|
||||
CalendarGridBody,
|
||||
CalendarGridHeader,
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
} from "@heroui-vue/components";
|
||||
import type { CalendarRangeModel } from "../../../packages/vue/src/components/date/range-selection";
|
||||
const initial = new CalendarDate(2024, 2, 10);
|
||||
const value = shallowRef<CalendarRangeModel>(null),
|
||||
changes = shallowRef(0),
|
||||
rejected = shallowRef(0);
|
||||
const initialRange = { start: initial, end: initial.add({ days: 5 }) };
|
||||
</script>
|
||||
<template>
|
||||
<main class="range-foundation-lab">
|
||||
<h1>RangeCalendar · 私有基建验收</h1>
|
||||
<p>尚未公开组件;这里只验证共享日期视图、范围状态和手势。</p>
|
||||
<div class="range-lab-grid">
|
||||
<section id="range-basic">
|
||||
<h2>选择 / 拖动 / 键盘</h2>
|
||||
<Range
|
||||
v-model="value"
|
||||
:default-focused-value="initial"
|
||||
time-zone="UTC"
|
||||
aria-label="基础日期范围"
|
||||
@change="changes++"
|
||||
/>
|
||||
<output>
|
||||
已接受:{{ value ? `${value.start} → ${value.end}` : "空" }};提交
|
||||
{{ changes }} 次
|
||||
</output>
|
||||
<Button
|
||||
size="sm"
|
||||
variant="secondary"
|
||||
@click="
|
||||
value = null;
|
||||
changes = 0;
|
||||
"
|
||||
>
|
||||
清空接受值
|
||||
</Button>
|
||||
</section>
|
||||
<section id="range-barrier">
|
||||
<h2>12 日不可用,禁止跨越</h2>
|
||||
<Range
|
||||
:default-focused-value="initial"
|
||||
time-zone="UTC"
|
||||
aria-label="不可用日期范围"
|
||||
:is-date-unavailable="(d) => d.day === 12"
|
||||
/>
|
||||
</section>
|
||||
<section id="range-rejected">
|
||||
<h2>受控拒绝(拖动端点可重试)</h2>
|
||||
<Range
|
||||
:model-value="initialRange"
|
||||
:default-focused-value="initial"
|
||||
time-zone="UTC"
|
||||
aria-label="拒绝提案的日期范围"
|
||||
@change="rejected++"
|
||||
/>
|
||||
<output>拒绝提案 {{ rejected }} 次</output>
|
||||
</section>
|
||||
<section id="range-multiple">
|
||||
<h2>两个月共享同一范围 / 焦点</h2>
|
||||
<Range
|
||||
:default-focused-value="initial"
|
||||
:visible-duration="{ months: 2 }"
|
||||
selection-alignment="start"
|
||||
class="range-lab-wide"
|
||||
aria-label="两个月的日期范围"
|
||||
>
|
||||
<CalendarHeader>
|
||||
<CalendarHeading />
|
||||
<CalendarNavButton slot="previous" />
|
||||
<CalendarNavButton slot="next" />
|
||||
</CalendarHeader>
|
||||
<div class="range-lab-months">
|
||||
<CalendarGrid>
|
||||
<CalendarGridHeader />
|
||||
<CalendarGridBody />
|
||||
</CalendarGrid>
|
||||
<CalendarGrid :offset="{ months: 1 }">
|
||||
<CalendarGridHeader />
|
||||
<CalendarGridBody />
|
||||
</CalendarGrid>
|
||||
</div>
|
||||
</Range>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
<style>
|
||||
.range-foundation-lab {
|
||||
padding: 32px;
|
||||
font-family: Inter, sans-serif;
|
||||
color: var(--foreground);
|
||||
background: var(--background);
|
||||
min-height: 100vh;
|
||||
}
|
||||
.range-foundation-lab h1 {
|
||||
font-size: 24px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.range-foundation-lab h2 {
|
||||
font-size: 14px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
.range-foundation-lab p {
|
||||
color: var(--muted);
|
||||
margin-bottom: 28px;
|
||||
}
|
||||
.range-lab-grid {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 40px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
.range-lab-grid section {
|
||||
padding: 20px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 16px;
|
||||
}
|
||||
.range-lab-grid output {
|
||||
display: block;
|
||||
margin: 16px 0;
|
||||
font-size: 12px;
|
||||
}
|
||||
.range-lab-wide {
|
||||
width: 524px;
|
||||
max-width: 100%;
|
||||
}
|
||||
.range-lab-months {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
}
|
||||
.range-lab-months > table {
|
||||
width: 252px;
|
||||
}
|
||||
</style>
|
||||
@@ -10,11 +10,8 @@ body {
|
||||
margin: 0;
|
||||
font-family: "Avenir Next", "Segoe UI", "PingFang SC", sans-serif;
|
||||
}
|
||||
button,
|
||||
input {
|
||||
font: inherit;
|
||||
}
|
||||
a {
|
||||
.lab > header a,
|
||||
.lab .text-link {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
@@ -26,7 +23,7 @@ a {
|
||||
background 0.2s,
|
||||
color 0.2s;
|
||||
}
|
||||
header {
|
||||
.lab > header {
|
||||
max-width: 1240px;
|
||||
margin: auto;
|
||||
padding: 28px 48px;
|
||||
@@ -53,7 +50,7 @@ header {
|
||||
background: var(--default);
|
||||
margin-left: 8px;
|
||||
}
|
||||
nav {
|
||||
.lab > header > nav {
|
||||
display: flex;
|
||||
gap: 30px;
|
||||
font-size: 14px;
|
||||
@@ -65,7 +62,7 @@ nav {
|
||||
font-size: 13px;
|
||||
color: var(--muted);
|
||||
}
|
||||
main {
|
||||
.lab > main {
|
||||
max-width: 1240px;
|
||||
margin: auto;
|
||||
padding: 0 48px;
|
||||
@@ -78,7 +75,7 @@ main {
|
||||
color: var(--muted);
|
||||
margin: 0 0 22px;
|
||||
}
|
||||
h1 {
|
||||
.lab h1 {
|
||||
font-size: clamp(40px, 5.4vw, 68px);
|
||||
font-weight: 650;
|
||||
line-height: 1.18;
|
||||
@@ -249,22 +246,22 @@ footer {
|
||||
}
|
||||
}
|
||||
@media (max-width: 640px) {
|
||||
header {
|
||||
.lab > header {
|
||||
padding: 20px 22px;
|
||||
}
|
||||
nav {
|
||||
.lab > header > nav {
|
||||
display: none;
|
||||
}
|
||||
.theme {
|
||||
font-size: 12px;
|
||||
}
|
||||
main {
|
||||
.lab > main {
|
||||
padding: 0 22px;
|
||||
}
|
||||
.intro {
|
||||
padding: 50px 0;
|
||||
}
|
||||
h1 {
|
||||
.lab h1 {
|
||||
letter-spacing: -1.5px;
|
||||
}
|
||||
.grid {
|
||||
|
||||
+89
-85
@@ -2,91 +2,91 @@
|
||||
|
||||
基于固定上游提交的公共组件导出清单。验证中不等于完整兼容;目前没有组件完成视觉、浏览器与完整行为验收。
|
||||
|
||||
| 组件 | 状态 | 当前能力 / 差异 |
|
||||
| -------------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| accordion | 验证中(M23) | Accordion/Item/Heading/Trigger/Panel/Body/Indicator;10/10 基线例;surface/hideSeparator;复用组键协议 |
|
||||
| alert-dialog | 验证中(M33) | 11 部件;role=alertdialog;默认不误关;14/14 基线例;Reka Dialog 底座 |
|
||||
| autocomplete | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| avatar | 验证中(最小实现) | Reka Avatar 加载/回退;size/color/variant;Image asChild;AvatarGroup 继承仅限直接子级 |
|
||||
| avatar-group | 验证中(最小实现) | max 截断与自动计数、显式 Count 不受截断、isGrid、overlap clip/ring;默认无 role=group |
|
||||
| badge | 验证中(最小实现) | Badge/BadgeAnchor/BadgeLabel;四角定位、圆点、文本/数字自动包装;Anchor 非链接 |
|
||||
| breadcrumbs | 验证中(M17) | Breadcrumbs/BreadcrumbsItem;7/7 基线例;ol+aria-label、末项 current、禁用/无 href span、separator 插槽;onAction 未提供,class 同时落 li/link |
|
||||
| button | 验证中(最小实现) | 基线全部 7 种变体、尺寸、isIconOnly/isDisabled/isPending;PressEvent 与 Vue click 差异见文档 |
|
||||
| button-group | 验证中(M26) | ButtonGroup/ButtonGroupSeparator;9/9 基线例;直接子 Button 继承 size/variant/isDisabled/fullWidth;嵌套不继承;圆角与 outline 边框处理 |
|
||||
| card | 验证中(最小实现) | 4 种表面变体;Header/Title/Description/Content/Footer 已实现;以基线 CSS 为准 |
|
||||
| checkbox | 验证中(基线实现) | 原生 label/input;checked/isSelected、半选、primary/secondary、Content/Control/Indicator;15 个基线预览 |
|
||||
| checkbox-group | 验证中(基线实现) | 数组模型、同名重复提交、required/readonly/disabled/reset、组标签与成员描述隔离;10 个基线预览 |
|
||||
| chip | 验证中(最小实现) | color/size/variant;纯文本/数字自动包装为 ChipLabel;显式部件不重复包装;组合内容可动态切换 |
|
||||
| color-area | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-slider | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-swatch | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-swatch-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| close-button | 验证中(最小实现) | 专用 CSS/变体、默认基线 CloseIcon、插槽替换图标、isDisabled、aria-label 默认 Close;onPress 由 click 适配 |
|
||||
| combo-box | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| date-field | 已迁移(有已知差异) | DateField 七部件与 DateInputGroup 六部件、17 预览;完整 ISO、字段校验、reset、SSR/水合与浏览器重点检查,见 DATE-02 报告;本地化整日期粘贴、13 月/era 编辑等仍待专项。 |
|
||||
| date-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| date-range-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| drawer | 验证中(M34) | 11 部件;四方向拖动关闭(30%/0.5px/ms);9/9 基线例;Content/Dialog 职责分离 |
|
||||
| progress-bar | 验证中(M18) | ProgressBar/Output/Track/Fill;7/7 基线例;确定/未知进度、min/max/formatOptions/valueLabel;custom-value 的 NumberField/Select 为原生临时控件 |
|
||||
| progress-circle | 验证中(M19) | ProgressCircle/Track/TrackCircle/FillCircle;7/7 基线例;圆环几何可覆盖;与 ProgressBar 共用取值语义 |
|
||||
| time-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| disclosure | 验证中(M21) | Disclosure/Heading/Trigger/Content/Body/Indicator;3/3 基线例;v-model:expanded;asChild 触发;高度动画映射测量变量 |
|
||||
| disclosure-group | 验证中(M22) | DisclosureGroup + useDisclosureGroupNavigation;3/3 基线例;展开键为数组(string 或 number);单选替换/多选增量 |
|
||||
| error-message | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| kbd | 验证中(最小实现) | variant;KbdAbbr keyValue 映射与 title;KbdContent;上下文类名;导出 kbdKeysMap/LabelMap |
|
||||
| link | 验证中(最小实现) | 原生 a + LinkIcon;isDisabled/asChild/焦点与 data 状态;默认图标为基线 ExternalLinkIcon;onPress 由 click 适配 |
|
||||
| popover | 验证中(OVERLAY-02) | Root/Trigger/Content/Dialog/Heading/Arrow;6/6 基线例;逻辑定位/碰撞/退出/标题;模态 closeAutoFocus 不支持取消恢复,见 OVERLAY-02 |
|
||||
| scroll-shadow | 验证中(M24) | 7/7 基线例;fade/方向/尺寸/偏移/受控可见性;VueUse 测量与公开 useScrollShadow,RTL/动态内容;CSS scroll timeline 保留 |
|
||||
| separator | 验证中(最小实现) | orientation/variant/decorative;默认 hr + role=separator;asChild 自定义根;Reka Separator |
|
||||
| skeleton | 验证中(最小实现) | shimmer/pulse/none、--skeleton-animation 全局默认、父级单次 shimmer;挂载后改 CSS 变量不自动更新 |
|
||||
| spinner | 验证中(最小实现) | size/color 变体、role=status、内置渐变 SVG;嵌入 Button 保持 16px;reduced-motion 支持 |
|
||||
| surface | 验证中(最小实现) | 4 种变体、data-slot、surfaceContextKey 提供当前变体;Input 文档表面示例已替换为 Surface |
|
||||
| toast | 验证中(M35) | Provider/Toast/Content/Indicator/Title/Description/Action/Close + 队列;11/11 例;自有计时(无双倒计时) |
|
||||
| toggle-button | 验证中(M27) | ToggleButton;7/7 基线例;v-model/isSelected/defaultSelected;data-selected/pressed/hover/focus;Enter/Space;组内 radio 语义 |
|
||||
| switch | 验证中(最小实现) | 根字段与组合部件、3 尺寸、ARIA 透传、原生/ARIA 校验、FormData/reset;PressEvent 不等价 |
|
||||
| switch-group | 验证中(布局) | vertical/horizontal;不共享选择值,已移植基线 CSS |
|
||||
| tabs | 验证中(M25) | 七部件、10/10 基线例;primary/secondary、方向/对齐、受控/键盘/禁用/滚动/指示器;Vue 模型与 ID/集合差异见报告 |
|
||||
| tag | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| tag-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| toggle-button-group | 验证中(M28) | ToggleButtonGroup/Separator;10/10 基线例;single/multiple、disallowEmptySelection、roving focus;Vue 数组模型替代 Set<Key> |
|
||||
| toolbar | 验证中(M29) | Toolbar;5/5 基线例;isAttached/orientation/dir;跨组单 Tab 入口与方向键;子组焦点让位;Separator 垂直继承 |
|
||||
| tooltip | 验证中(OVERLAY-02) | Root/Trigger/Content/Arrow;6/6 基线例;CSS 延迟/焦点/禁用/替换/定位;Provider warmup 与 RAC 全局调度不同 |
|
||||
| input | 验证中(字段接入) | 接入 TextField;复用值恢复/reset/ARIA;独立使用保持兼容;完整消费验收未完成 |
|
||||
| input-group | 验证中(字段接入) | Root/Input/TextArea/Prefix/Suffix;复用 useTextControl;变体继承 TextField 可覆盖;前后缀非表单字段 |
|
||||
| textarea | 验证中(字段接入) | rows 默认 3;变体/fullWidth/受控/FormData/reset;独立页 7/7 示例;接入 useTextControl |
|
||||
| textfield | 验证中(字段接入) | 值/状态/约束/校验/ID;独立页 13/13 示例;render 自定义根类型未支持(data-* 透传) |
|
||||
| search-field | 验证中(FORM-02) | 五部件、15 基线例;共享文本内核、clear/submit/IME/reset/SSR,边界见 FORM-02 |
|
||||
| typography | 验证中(M15) | Typography/Heading/Paragraph/Code/Prose 具名导出;6/6 基线例;type/as/align/color/weight/truncate;render 映射为 as |
|
||||
| label | 验证中(通用字段) | 自动 for、Switch 内 span、状态继承;独立页 2/2 示例 |
|
||||
| description | 验证中(通用字段) | 动态 ID 清理、外部 describedby 合并;独立页 2/2 示例;SSR 包装限制见基础协议 |
|
||||
| empty-state | 验证中(M16) | 单根 EmptyState;4 个自编示例(基线无页面/示例);默认 fallback;空节点判断与上游 children 真值回退边界不同 |
|
||||
| field-error | 验证中(通用字段) | 作用域插槽 validationErrors;独立页 2/2 示例;无完整 validationDetails(见基础协议) |
|
||||
| fieldset | 验证中(FORM-02) | 四部件、3 基线例与禁用验证例;响应式禁用、首 Legend 例外,边界见 FORM-02 |
|
||||
| form | 验证中(基础设施) | native/aria 校验、FormData/reset、服务端错误;完整基线文档与生态集成未完成 |
|
||||
| header | 验证中(M31) | Header/HeaderRoot;原生 `<header>` 集合分组标题;基线无独立文档/演示,自编 3 例并标注;无 v-model |
|
||||
| radio | 验证中(基线实现) | 原生 radio + Content/Control/Indicator;须在 RadioGroup 内,成员禁用/只读、作用域状态 |
|
||||
| radio-group | 验证中(基线实现) | 标量模型、roving Tab/方向键/dir/loop、原生提交/校验/reset;12 个基线预览 |
|
||||
| input-otp | 验证中(M32) | Root/Group/Slot/Separator + 3 正则常量;Reka PinInput 底座;字符串+索引数组;reset/Fieldset/Form/ARIA/mask 已接入;11/11 例;自动填充/IME/读屏未真机验证 |
|
||||
| alert | 验证中(最小实现) | status 五态;默认图标随 status;自定义 Indicator 空内容回退;内部 Surface 重置为 default |
|
||||
| list-box | 验证中(LISTBOX-01) | 四部件、9/9 基线例;typed key/数组模型、none/single/multiple、键盘/范围/全选、1000 项固定行高虚拟化;差异见 LISTBOX-01 |
|
||||
| list-box-item | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
|
||||
| list-box-section | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
|
||||
| dropdown | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu-item | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu-section | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| modal | 验证中(OVERLAY-02) | Root/Trigger/Backdrop/Container/Dialog/Heading/Header/Body/Footer/Icon/Close/CloseTrigger;14/14 基线例;焦点/锁/滚动/退出动画;Vue close 部件替代 React slot |
|
||||
| pagination | 验证中(M30) | 组合式 nav 容器(无 total/page 状态机);11 具名部件;9/9 基线例;onPress→@click;显式 aria-current 可覆盖 |
|
||||
| number-field | 验证中(NUMBER-01) | 五部件与 17/17 基线例;Reka 数值内核;受控/只读/表单 reset、SSR/水合;差异见 NUMBER-01 报告 |
|
||||
| select | 验证中(SELECT-01) | 六部件、19/19 例、单/多选、清空、字段/原生提交/SSR/异步;复用 ListBox + Popover,重点浏览器已验,限制见 SELECT-01 |
|
||||
| meter | 验证中(M20) | Meter/Output/Track/Fill;6/6 基线例;role=meter progressbar;无 isIndeterminate;测量语义独立于 Progress |
|
||||
| slider | 验证中(SLIDER-01) | 六部件、9/9 基线例;原生 range/局部指针适配,单值/范围、受控/reset/SSR/水合;差异见 SLIDER-01 |
|
||||
| table | 验证中(M36 部分) | 15 部件;选择/排序/原生语义;13 演示;虚拟化/列拖动/TanStack 未完整,见 M36 |
|
||||
| calendar | 已迁移(有已知差异) | 月/周/日、多选、焦点/翻页、国际历法、年份层与 19 预览;局部日期视图/键盘适配,默认历法边界等差异见 DATE-03。 |
|
||||
| range-calendar | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| calendar-year-picker | 已迁移(DATE-03) | 六个独立具名部件、三列年份、窗口/格式/era、覆盖测量、焦点与关闭;不导出 React 上下文。 |
|
||||
| 组件 | 状态 | 当前能力 / 差异 |
|
||||
| -------------------- | ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| accordion | 验证中(M23) | Accordion/Item/Heading/Trigger/Panel/Body/Indicator;10/10 基线例;surface/hideSeparator;复用组键协议 |
|
||||
| alert-dialog | 验证中(M33) | 11 部件;role=alertdialog;默认不误关;14/14 基线例;Reka Dialog 底座 |
|
||||
| autocomplete | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| avatar | 验证中(最小实现) | Reka Avatar 加载/回退;size/color/variant;Image asChild;AvatarGroup 继承仅限直接子级 |
|
||||
| avatar-group | 验证中(最小实现) | max 截断与自动计数、显式 Count 不受截断、isGrid、overlap clip/ring;默认无 role=group |
|
||||
| badge | 验证中(最小实现) | Badge/BadgeAnchor/BadgeLabel;四角定位、圆点、文本/数字自动包装;Anchor 非链接 |
|
||||
| breadcrumbs | 验证中(M17) | Breadcrumbs/BreadcrumbsItem;7/7 基线例;ol+aria-label、末项 current、禁用/无 href span、separator 插槽;onAction 未提供,class 同时落 li/link |
|
||||
| button | 验证中(最小实现) | 基线全部 7 种变体、尺寸、isIconOnly/isDisabled/isPending;PressEvent 与 Vue click 差异见文档 |
|
||||
| button-group | 验证中(M26) | ButtonGroup/ButtonGroupSeparator;9/9 基线例;直接子 Button 继承 size/variant/isDisabled/fullWidth;嵌套不继承;圆角与 outline 边框处理 |
|
||||
| card | 验证中(最小实现) | 4 种表面变体;Header/Title/Description/Content/Footer 已实现;以基线 CSS 为准 |
|
||||
| checkbox | 验证中(基线实现) | 原生 label/input;checked/isSelected、半选、primary/secondary、Content/Control/Indicator;15 个基线预览 |
|
||||
| checkbox-group | 验证中(基线实现) | 数组模型、同名重复提交、required/readonly/disabled/reset、组标签与成员描述隔离;10 个基线预览 |
|
||||
| chip | 验证中(最小实现) | color/size/variant;纯文本/数字自动包装为 ChipLabel;显式部件不重复包装;组合内容可动态切换 |
|
||||
| color-area | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-slider | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-swatch | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| color-swatch-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| close-button | 验证中(最小实现) | 专用 CSS/变体、默认基线 CloseIcon、插槽替换图标、isDisabled、aria-label 默认 Close;onPress 由 click 适配 |
|
||||
| combo-box | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| date-field | 已迁移(有已知差异) | DateField 七部件与 DateInputGroup 六部件、17 预览;完整 ISO、字段校验、reset、SSR/水合与浏览器重点检查,见 DATE-02 报告;本地化整日期粘贴、13 月/era 编辑等仍待专项。 |
|
||||
| date-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| date-range-picker | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| drawer | 验证中(M34) | 11 部件;四方向拖动关闭(30%/0.5px/ms);9/9 基线例;Content/Dialog 职责分离 |
|
||||
| progress-bar | 验证中(M18) | ProgressBar/Output/Track/Fill;7/7 基线例;确定/未知进度、min/max/formatOptions/valueLabel;custom-value 的 NumberField/Select 为原生临时控件 |
|
||||
| progress-circle | 验证中(M19) | ProgressCircle/Track/TrackCircle/FillCircle;7/7 基线例;圆环几何可覆盖;与 ProgressBar 共用取值语义 |
|
||||
| time-field | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| disclosure | 验证中(M21) | Disclosure/Heading/Trigger/Content/Body/Indicator;3/3 基线例;v-model:expanded;asChild 触发;高度动画映射测量变量 |
|
||||
| disclosure-group | 验证中(M22) | DisclosureGroup + useDisclosureGroupNavigation;3/3 基线例;展开键为数组(string 或 number);单选替换/多选增量 |
|
||||
| error-message | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| kbd | 验证中(最小实现) | variant;KbdAbbr keyValue 映射与 title;KbdContent;上下文类名;导出 kbdKeysMap/LabelMap |
|
||||
| link | 验证中(最小实现) | 原生 a + LinkIcon;isDisabled/asChild/焦点与 data 状态;默认图标为基线 ExternalLinkIcon;onPress 由 click 适配 |
|
||||
| popover | 验证中(OVERLAY-02) | Root/Trigger/Content/Dialog/Heading/Arrow;6/6 基线例;逻辑定位/碰撞/退出/标题;模态 closeAutoFocus 不支持取消恢复,见 OVERLAY-02 |
|
||||
| scroll-shadow | 验证中(M24) | 7/7 基线例;fade/方向/尺寸/偏移/受控可见性;VueUse 测量与公开 useScrollShadow,RTL/动态内容;CSS scroll timeline 保留 |
|
||||
| separator | 验证中(最小实现) | orientation/variant/decorative;默认 hr + role=separator;asChild 自定义根;Reka Separator |
|
||||
| skeleton | 验证中(最小实现) | shimmer/pulse/none、--skeleton-animation 全局默认、父级单次 shimmer;挂载后改 CSS 变量不自动更新 |
|
||||
| spinner | 验证中(最小实现) | size/color 变体、role=status、内置渐变 SVG;嵌入 Button 保持 16px;reduced-motion 支持 |
|
||||
| surface | 验证中(最小实现) | 4 种变体、data-slot、surfaceContextKey 提供当前变体;Input 文档表面示例已替换为 Surface |
|
||||
| toast | 验证中(M35) | Provider/Toast/Content/Indicator/Title/Description/Action/Close + 队列;11/11 例;自有计时(无双倒计时) |
|
||||
| toggle-button | 验证中(M27) | ToggleButton;7/7 基线例;v-model/isSelected/defaultSelected;data-selected/pressed/hover/focus;Enter/Space;组内 radio 语义 |
|
||||
| switch | 验证中(最小实现) | 根字段与组合部件、3 尺寸、ARIA 透传、原生/ARIA 校验、FormData/reset;PressEvent 不等价 |
|
||||
| switch-group | 验证中(布局) | vertical/horizontal;不共享选择值,已移植基线 CSS |
|
||||
| tabs | 验证中(M25) | 七部件、10/10 基线例;primary/secondary、方向/对齐、受控/键盘/禁用/滚动/指示器;Vue 模型与 ID/集合差异见报告 |
|
||||
| tag | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| tag-group | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| toggle-button-group | 验证中(M28) | ToggleButtonGroup/Separator;10/10 基线例;single/multiple、disallowEmptySelection、roving focus;Vue 数组模型替代 Set<Key> |
|
||||
| toolbar | 验证中(M29) | Toolbar;5/5 基线例;isAttached/orientation/dir;跨组单 Tab 入口与方向键;子组焦点让位;Separator 垂直继承 |
|
||||
| tooltip | 验证中(OVERLAY-02) | Root/Trigger/Content/Arrow;6/6 基线例;CSS 延迟/焦点/禁用/替换/定位;Provider warmup 与 RAC 全局调度不同 |
|
||||
| input | 验证中(字段接入) | 接入 TextField;复用值恢复/reset/ARIA;独立使用保持兼容;完整消费验收未完成 |
|
||||
| input-group | 验证中(字段接入) | Root/Input/TextArea/Prefix/Suffix;复用 useTextControl;变体继承 TextField 可覆盖;前后缀非表单字段 |
|
||||
| textarea | 验证中(字段接入) | rows 默认 3;变体/fullWidth/受控/FormData/reset;独立页 7/7 示例;接入 useTextControl |
|
||||
| textfield | 验证中(字段接入) | 值/状态/约束/校验/ID;独立页 13/13 示例;render 自定义根类型未支持(data-* 透传) |
|
||||
| search-field | 验证中(FORM-02) | 五部件、15 基线例;共享文本内核、clear/submit/IME/reset/SSR,边界见 FORM-02 |
|
||||
| typography | 验证中(M15) | Typography/Heading/Paragraph/Code/Prose 具名导出;6/6 基线例;type/as/align/color/weight/truncate;render 映射为 as |
|
||||
| label | 验证中(通用字段) | 自动 for、Switch 内 span、状态继承;独立页 2/2 示例 |
|
||||
| description | 验证中(通用字段) | 动态 ID 清理、外部 describedby 合并;独立页 2/2 示例;SSR 包装限制见基础协议 |
|
||||
| empty-state | 验证中(M16) | 单根 EmptyState;4 个自编示例(基线无页面/示例);默认 fallback;空节点判断与上游 children 真值回退边界不同 |
|
||||
| field-error | 验证中(通用字段) | 作用域插槽 validationErrors;独立页 2/2 示例;无完整 validationDetails(见基础协议) |
|
||||
| fieldset | 验证中(FORM-02) | 四部件、3 基线例与禁用验证例;响应式禁用、首 Legend 例外,边界见 FORM-02 |
|
||||
| form | 验证中(基础设施) | native/aria 校验、FormData/reset、服务端错误;完整基线文档与生态集成未完成 |
|
||||
| header | 验证中(M31) | Header/HeaderRoot;原生 `<header>` 集合分组标题;基线无独立文档/演示,自编 3 例并标注;无 v-model |
|
||||
| radio | 验证中(基线实现) | 原生 radio + Content/Control/Indicator;须在 RadioGroup 内,成员禁用/只读、作用域状态 |
|
||||
| radio-group | 验证中(基线实现) | 标量模型、roving Tab/方向键/dir/loop、原生提交/校验/reset;12 个基线预览 |
|
||||
| input-otp | 验证中(M32) | Root/Group/Slot/Separator + 3 正则常量;Reka PinInput 底座;字符串+索引数组;reset/Fieldset/Form/ARIA/mask 已接入;11/11 例;自动填充/IME/读屏未真机验证 |
|
||||
| alert | 验证中(最小实现) | status 五态;默认图标随 status;自定义 Indicator 空内容回退;内部 Surface 重置为 default |
|
||||
| list-box | 验证中(LISTBOX-01) | 四部件、9/9 基线例;typed key/数组模型、none/single/multiple、键盘/范围/全选、1000 项固定行高虚拟化;差异见 LISTBOX-01 |
|
||||
| list-box-item | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
|
||||
| list-box-section | 验证中(LISTBOX-01) | ListBox 子部件;独立标签/描述作用域、自动分组名称、原生标签替换、状态/指示器;见 LISTBOX-01 |
|
||||
| dropdown | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu-item | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| menu-section | 计划 | 待实施时核验子部件、属性、事件、键盘行为与替代底座 |
|
||||
| modal | 验证中(OVERLAY-02) | Root/Trigger/Backdrop/Container/Dialog/Heading/Header/Body/Footer/Icon/Close/CloseTrigger;14/14 基线例;焦点/锁/滚动/退出动画;Vue close 部件替代 React slot |
|
||||
| pagination | 验证中(M30) | 组合式 nav 容器(无 total/page 状态机);11 具名部件;9/9 基线例;onPress→@click;显式 aria-current 可覆盖 |
|
||||
| number-field | 验证中(NUMBER-01) | 五部件与 17/17 基线例;Reka 数值内核;受控/只读/表单 reset、SSR/水合;差异见 NUMBER-01 报告 |
|
||||
| select | 验证中(SELECT-01) | 六部件、19/19 例、单/多选、清空、字段/原生提交/SSR/异步;复用 ListBox + Popover,重点浏览器已验,限制见 SELECT-01 |
|
||||
| meter | 验证中(M20) | Meter/Output/Track/Fill;6/6 基线例;role=meter progressbar;无 isIndeterminate;测量语义独立于 Progress |
|
||||
| slider | 验证中(SLIDER-01) | 六部件、9/9 基线例;原生 range/局部指针适配,单值/范围、受控/reset/SSR/水合;差异见 SLIDER-01 |
|
||||
| table | 验证中(M36 部分) | 15 部件;选择/排序/原生语义;13 演示;虚拟化/列拖动/TanStack 未完整,见 M36 |
|
||||
| calendar | 已迁移(有已知差异) | 月/周/日、多选、焦点/翻页、国际历法、年份层与 19 预览;局部日期视图/键盘适配,默认历法边界等差异见 DATE-03。 |
|
||||
| range-calendar | 私有基建已验证(DATE-04) | 接受值/草稿、障碍、共享视图与鼠标拖动已验证;尚未公开部件或 20 个正式预览,见 DATE-04 |
|
||||
| calendar-year-picker | 已迁移(DATE-03) | 六个独立具名部件、三列年份、窗口/格式/era、覆盖测量、焦点与关闭;不导出 React 上下文。 |
|
||||
|
||||
## 公共导出差异
|
||||
|
||||
@@ -214,3 +214,7 @@ Toast 11/11 与 Table 13/13 预览、各部件 Props、文档和默认源样式
|
||||
## DATE-03 Calendar / YearPicker
|
||||
|
||||
本轮恢复日期迁移并公开 Calendar/CalendarRoot、日期九部件与 YearPicker 六部件、十九个预览。范围、底座适配依据、DOM/模型/年份层契约及尚未验收能力见 [DATE-03](migrations/DATE-03-calendar.md)。本轮不完成其他日期/时间/颜色组件。
|
||||
|
||||
## DATE-04 范围选择基建
|
||||
|
||||
共享日历视图已提取,私有范围选择与手势经过集成、SSR、水合和重点浏览器验证;这不代表 RangeCalendar 公共迁移完成。当前范围、触屏长按拖选与字段组合的待办见 [DATE-04](migrations/DATE-04-range-foundation.md),公开收尾交接见 [DATE-05 提示词](migrations/DATE-05-range-calendar-prompt.md)。
|
||||
|
||||
@@ -77,3 +77,7 @@ Calendar 键盘探针同时发送 key/code;安装版用 code 导航。只发 k
|
||||
## DATE-03 接续
|
||||
|
||||
2026-10-24 用户明确恢复集成人迁移。Calendar/YearPicker 已实施公开部件、十九例和局部视图/键盘适配;前述暂停及“只有探针”属于历史阶段。单一模式所有者的取舍、真实差异与验收边界见 [DATE-03](../migrations/DATE-03-calendar.md),Range/Picker/Time 不在本轮完成。
|
||||
|
||||
## DATE-04 接续与分工收紧
|
||||
|
||||
2026-10-25 按用户要求集中完成复杂内核。Calendar view/focus/year owner 已从 Root 提取,RangeCalendar 的接受值与锚点/预览/鼠标手势接入同一 owner;不是复制整套月历。当前只有私有集成夹具,公开壳层及 20 个预览交给其他 AI,见 [DATE-04](../migrations/DATE-04-range-foundation.md) 和 [DATE-05](../migrations/DATE-05-range-calendar-prompt.md)。触屏长按、范围字段/Picker/Time 桥接与颜色内核仍由集成人验证,不从 Calendar 成功推断这些边界已完成。
|
||||
|
||||
@@ -318,3 +318,11 @@ DateField 七部件与 DateInputGroup 六部件、17 例已落地,范围和差
|
||||
## DATE-03 集成人接续
|
||||
|
||||
用户恢复日期迁移:Calendar/CalendarYearPicker 的公开部件与 19 个示例已落地,底座缺口使用共享日期视图/键盘薄适配,见 [DATE-03](migrations/DATE-03-calendar.md)。其他 AI 不改写 date/calendar 或 calendar/context;RangeCalendar、Picker/TimeField 由集成人继续。先前暂停日历的文字仅为文档优化阶段记录。
|
||||
|
||||
## DATE-04:范围内核就绪后的分工(2026-10-25)
|
||||
|
||||
用户明确要求集成人集中处理复杂组件与架构风险,可复用基建稳定后交出公开收尾。当前可派发任务为 [DATE-05 RangeCalendar 公共迁移](migrations/DATE-05-range-calendar-prompt.md),先同步最新 main 再新建 feat/date-05-range-calendar-public。它消费 [DATE-04](migrations/DATE-04-range-foundation.md) 的私有内核,不修改或复制共享状态。
|
||||
|
||||
实际浏览器发现的重点:原生事件监听器间的微任务会提前清理手势;disabled 月外日期仍会收到 pointerenter;RAC 块容器与原生 button 的拉伸不同;验收页的全局 header/font 会污染真实组件。后续在实际事件/Cell 状态/几何上回归,不能仅凭 jsdom 绿色或源 CSS 数值判断。
|
||||
|
||||
本轮只交 RangeCalendar 公共壳层、20 例、文档/产物契约;不让其他 AI 顺带重建 Picker/Time 的提交/reset 桥接或触屏长按手势。日期字段适配及 ColorArea/ColorPicker 的共享状态仍由集成人负责,先补探针后决定可派发范围。
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
# DATE-04:RangeCalendar 范围选择基建
|
||||
|
||||
2026-10-25,独立目录 heroui-vue-core,从已同步 main `5c4375a` 新建 `feat/range-calendar-foundation`。用户要求集成人集中处理复杂交互和重要基建,常规公开壳层、完整文档与示例交给其他 AI。本轮按此拆分,**没有公开 RangeCalendar 或把它标为迁移完成**。
|
||||
|
||||
## 来源与边界
|
||||
|
||||
固定 HeroUI 3.2.6 / ce90ea3 的 range-calendar.tsx、range-calendar.css/tv、中文正文和 20 个预览。当前已存在的 Calendar/YearPicker、date/value、choice 及字段/弹层协议继续复用。没有新增 UI 底座、React 依赖或修改相邻 checkout。
|
||||
|
||||
另外阅读了 Adobe 官方 [useRangeCalendarState](https://github.com/adobe/react-spectrum/blob/main/packages/react-stately/src/calendar/useRangeCalendarState.ts) 和 [useCalendarCell](https://github.com/adobe/react-spectrum/blob/main/packages/react-aria/src/calendar/useCalendarCell.ts),用于核对完整值、临时锚点、不可用日期和拖动端点的语义;这是当日辅助审计,不能替代固定 HeroUI 基线。没有移植 React hook 实现。
|
||||
|
||||
## 已落地的内核
|
||||
|
||||
| 文件 | 所有权与契约 |
|
||||
| ------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `packages/vue/src/components/calendar/view.ts` | 从 Calendar.vue 提取唯一视图/焦点/翻页/年份层所有者;原 Calendar 单/多选保留自己的选择策略。范围模式复用它,禁止复制成另一套键盘或月份状态。 |
|
||||
| `packages/vue/src/components/date/range-selection.ts` | 完整接受值与不完整草稿分离;本地日排序、范围成员判断、内部障碍检测;起止端点各自保留原 calendar、日期类、时间精度与 zone,空模型提案为公历。 |
|
||||
| `packages/vue/src/components/range-calendar/use-range-calendar.ts` | 私有 RangeCalendarOptions、接受值、锚点/预览、选择与手势;通过 useChoiceValue 保持父值优先及拒绝后重试。 |
|
||||
| `calendar/context.ts` / `parts.ts` | 私有 range 手势桥和 namespace;同一原生 Cell 导航层生成范围端点/选区/错误状态,不在每个 Cell 保存另一份范围模型。CalendarCellState 增量提供 isSelectionStart/isSelectionEnd/isInvalid。 |
|
||||
| `calendar/year-picker.ts` | 按真实日历 namespace 测量日网格,年份部件仍使用独立 calendar-year-picker 名称与样式。 |
|
||||
| `packages/vue/tests/fixtures/RangeCalendarFoundation.vue` | 私有集成夹具,实际使用上述内核及现有日历部件;不是公共组件或正式文档预览。 |
|
||||
| `apps/playground/src/RangeCalendarFoundationLab.vue` | `?range-calendar-foundation` 真实浏览器验收入口,提供普通/障碍/拒绝/多月组合。 |
|
||||
|
||||
选择首次激活只建立草稿,第二次激活才发完整范围;同日和反向选择均支持。modelValue(含显式 null)优先于 value,defaultValue 捕获一次。父拒绝后立即恢复接受值显示,再次选择或拖动可产生同一提案;事件/插槽值复制,不能修改父日期。
|
||||
|
||||
键盘首次激活尝试前进一个可用日,展示范围预览;只有接受的 focusedValue 参与预览。Escape 清除草稿并恢复已接受选区。完成选择保留终点焦点,不因接受值的 start 改变又跳回起点。外部 focusedValue 仍是独立视图入口;程序修改范围不会隐式重写受控焦点。
|
||||
|
||||
isDateUnavailable 收到日期副本与 CalendarDate/null 锚点副本。不可用端点仍可聚焦、不能选择;连续模式阻止跨越内部障碍,allowsNonContiguousRanges 允许跨不可用日但不能选不可用端点,isDateDisabled 仍构成障碍。规则闭包中的响应式依赖必须生效,缓存不能只按回调引用失效。导航在障碍边界收敛,不能沿默认 200 年范围逐日死循环。
|
||||
|
||||
鼠标/笔支持拖动选择、拖动已选起止端点、外部释放/取消回滚;原生 click、keydown、pointerdown/pointerup 的取消按实际阶段处理。普通两次点击在 click 阶段确认,避免 pointerup 早于消费者 @click.prevent 就提交。监听只存在于当前手势,取消、禁用、只读、打开年份层、外部值替换和卸载均清理。
|
||||
|
||||
## 浏览器中实际发现并修复的问题
|
||||
|
||||
1. **捕获监听器后的微任务过早清理。** 浏览器可以在原生事件监听器之间执行微任务,document capture 的 queueMicrotask 会先于 Cell pointerup 清除拖动。改为整次派发后的 task,并在正常结束时取消清理任务;jsdom 不能代替此验证。
|
||||
2. **月外补位日期仍收到 pointerenter。** 即使原生按钮 disabled,仍可能收到指针事件;只有 base 日期边界判断不足以代表真实 Cell 的可操作状态。统一桥接先检查 Cell 的 outside-month/disabled/yearOpen,避免拖过补位日误翻月或提交重复日期。
|
||||
3. **原生 button 的宽度与 RAC 块节点不同。** Range CSS 增加 w-full 让日期按钮拉伸,恢复 36×36,而非十几像素的内容宽度;数值和范围轨道沿用源 CSS。
|
||||
4. **playground 全局规则污染组件。** header/main/nav/h1 收窄到旧 `.lab`,去除覆盖库字号的全局 button/input font 重置。不能为此在范围组件里反向覆盖演示布局。
|
||||
|
||||
## 当前验证
|
||||
|
||||
- 新增 28 项集成/行为/真实 jsdom 水合测试,另有 2 项真正 node SSR;默认回归命令已纳入。
|
||||
- 全量 75 个文件 / **921 项测试通过**;类型检查与库/文档构建通过。文档构建仍有已有大 chunk 提示。
|
||||
- Calendar 的已有 28 项回归仍通过;独立 tarball 的 Calendar/DateField/Select ESM、SSR、CSS 和 Calendar/DateField/Select 两种模块解析类型正反例作为共享重构回归,结果记录于 verification.md。
|
||||
- 5176 真实浏览器:鼠标拖 2 月 10–15 日只提交一次;普通两次点击首击无提交;受控边界拖动相同提案两次均发出、接受范围不变;键盘首次激活焦点推进;年份层与日网格同为 228px 且当前年聚焦可见;月外补位与外部释放回滚后保持 February 和已接受范围;日期按钮 36×36。
|
||||
- 截图保存于 `/private/tmp/heroui-range-foundation-review.png`,它是临时验收证据,不依赖此绝对路径构建。
|
||||
|
||||
## 未完成与交接
|
||||
|
||||
**可交给其他 AI:** 公开 RangeCalendar 十部件与六个 YearPicker 别名、全部 Props/类型/variants/包根导出;20 个完整基线 SFC;中文文档/API/样式参考、导航与产物契约。具体任务见 [下一轮提示词](DATE-05-range-calendar-prompt.md)。只能消费本轮内核,真实缺口交最小失败用例给集成人,不能自行复制或改写共享状态层。
|
||||
|
||||
**仍由集成人处理的边界:** 触屏长按拖动、范围字段/Picker 与 Time 对现有 DateField 的适配探针、颜色共享状态和拖动基础。本轮触屏仅保留原生滚动及 click/tap 选择路径,没有宣称已支持触屏长按拖选;不能由文档隐去这项差异。读屏范围提示/完成公告尚未接入公共壳层,下一轮要明确实现与支持的 locale,不可用 aria-selected 代替完整读屏验收。
|
||||
|
||||
本轮不产生表单 name/value 或 reset,也不提供 DateRangePicker/TimeField:Calendar 是选择视图;唯一原生提交和 reset 应由后续字段组合承载,不能在这里新增第二套 Form 协议。未做自动逐像素、完整读屏、物理触屏、Nuxt/全浏览器验收,不以内部夹具通过声明公开组件迁移完成。
|
||||
@@ -0,0 +1,33 @@
|
||||
# 下一轮:RangeCalendar 公共迁移收尾
|
||||
|
||||
以下正文可直接交给其他 AI。本任务基于 DATE-04 已验证的范围内核;尚未执行,不代表公开组件已完成。
|
||||
|
||||
```text
|
||||
请在你自己的 heroui-vue checkout 完成 RangeCalendar 的公共部件、完整文档及演示。先阅读 AGENTS.md、docs/migration-handoff.md、docs/migrations/DATE-04-range-foundation.md、日期基建决策及最近几轮迁移经验。不要修改集成人的 heroui-vue-core 或重启其服务。
|
||||
|
||||
开始前检查 git status,保留未提交源码和旧截图;有未完成修改先说明。fetch origin,切 main,pull --ff-only,再新建 feat/date-05-range-calendar-public。确保 main 包含 DATE-04 范围基建,不从旧分支继续写。
|
||||
|
||||
固定基线 HeroUI 3.2.6 / ce90ea3ab49d58f6c428f71bfd6fe8ae2a87b960。参考 ../heroui 中 range-calendar 的组件、index、CSS/tv、中文正文及 cn 演示。Vue 样式、结构、文案、参数和行为保持高度一致,差异明确登记。
|
||||
|
||||
复用 src/components/range-calendar/use-range-calendar.ts、date/range-selection.ts、calendar/view.ts 与现有 Calendar 部件/YearPicker。私有 RangeCalendarFoundation.vue 只是集成参考,不要把 tests 目录作为发布运行时依赖。Root 包装内核;日期十部件可基于同一共享实现给具名 RangeCalendar/RangeCalendarRoot/Header/Heading/NavButton/Grid/GridHeader/GridBody/HeaderCell/Cell/CellIndicator 导出。YearPicker 给六个具名 RangeCalendarYearPicker* 别名并复用原 CalendarYearPicker 实现。全部 Props、RangeCalendarOptions/完整模型/作用域插槽和 variants 从包根导出,类型名称核对既有风格。
|
||||
|
||||
禁止复制第二套选择、焦点、月/周/日、翻页或年份状态。禁止重写 choice/field/Form/overlay/date/calendar 共享内核。发现底座真实缺口时提交最小失败用例并说明影响,让集成人修;不要 as any/as never、乐观状态或假 ARIA 掩盖。
|
||||
|
||||
样式文件已从上游准备并接入样式入口,w-full 是原生 button 拉伸适配,保留它。补齐 tv slots,检查 src 与 CSS 导出。不要引入另一套日期库或自绘演示 SVG;自定义图标使用现有 Tabler Vue。
|
||||
|
||||
按中文正文准确完成 20 个同源 Vue SFC,顺序为:basic、disabled、year-picker、default-value、controlled、min-max-dates、unavailable-dates、anchor-unavailable-dates、weeks-in-month、week-view、day-view、allows-non-contiguous-ranges、read-only、invalid、focused-value、with-indicators、booking-calendar、multiple-months、international-calendar、custom-styles。核对每例实际内容,不以相同普通月历替代周/日/多月/预订。Select 等组合使用本库已有组件。
|
||||
|
||||
预览、复制、高亮来自同一 SFC。整页 API 和作用域表始终铺满容器,长内容换行,不横向滚动,Markdown 类型管道转义。导航共用 apps/docs/.vitepress/theme/navigation.ts 清单,正确归入日期组。文档服务 5173,不能杀其他服务或把旧 dist 当新实现。
|
||||
|
||||
公开模型只接受完整 {start: DateValue, end: DateValue} | null;首击锚点不是 change。v-model/modelValue(含 null)优先、value 别名、defaultValue 捕获、父拒绝重试、起止各自 calendar/时间/zone、不可用锚点回调、非连续范围、焦点受控拒绝及开关年份均按内核契约展示。Calendar 不产生第二套隐藏表单/reset;字段 Picker 不在本轮范围。
|
||||
|
||||
补齐 Root/Cell 的读屏操作提示及完成范围公告,采用明确的 locale 文案策略,避免一次动作重复公告;所有值和 ID 必须 SSR 稳定。触屏长按拖选尚未具备,由集成人后续处理;保留原生滚动、tap 路径及公开差异,不自行复制全局手势层,也不能写成已完整支持触屏拖动。
|
||||
|
||||
验证公共导出、Props 与 scoped slots 的真实类型约束;拒绝提案、单次提交、原生事件取消、动态 attrs/规则、多实例 ID、SSR 和真实水合都要断言。不得只检查组件仍挂载。所有 20 例同页挂载,核对事件、重复 ID 与控制台警告。
|
||||
|
||||
运行适用单元测试、全量测试、typecheck、build:docs、格式检查。独立打包产物安装到工作区之外,运行 Node ESM/SSR/CSS 和 bundler/NodeNext 正反类型检查(错误模型、日期类、持续时间、Props、事件/slot 参数),保留 Calendar/DateField/Select 消费回归。任何 unused expect-error 均为失败。
|
||||
|
||||
浏览器不用逐例点击;重点检查范围轨道/端点、鼠标拖动与取消、两个网格共享焦点、年份覆盖层和长短表;避免全局 header/button/table 样式污染。不要把 jsdom 或 CSS 源值当成实际布局证据。没有执行的读屏、真机、逐像素、Nuxt 检查明确列出。
|
||||
|
||||
更新 compatibility/upstream/verification,提交 docs/migrations/DATE-05-range-calendar.md:逐项原契约→实现→验证→差异、命令结果、浏览器证据、缺口和共享文件增量。不要提前声明全日期族迁移完成。完成后停在任务分支交回复核,未经复核不要合并 main 或推送 main。
|
||||
```
|
||||
@@ -202,3 +202,7 @@ M18–M20 的标签桥接在 Vue 使用 indicator 注册表与 SSR 直接/原生
|
||||
## DATE-03 Calendar / YearPicker(2026-10-24)
|
||||
|
||||
固定 ce90ea3 的 calendar、calendar-day-view-grid-body/header、calendar-year-picker、utils/calendar.ts、同名 CSS/tv、中文正文与 19 个演示。样式加 hv- 前缀并保留数值;默认箭头路径取自 icons.tsx,Apache-2.0 声明保留。Vue 的本地日期视图/键盘与既有接受值协议替代不能覆盖所有模式的安装版月历,未复制底层库实现或加入 React 依赖;实际差异与验证见 [DATE-03](migrations/DATE-03-calendar.md)。
|
||||
|
||||
## DATE-04 RangeCalendar 私有基建(2026-10-25)
|
||||
|
||||
核对 ce90ea3 的 range-calendar 组件、CSS/tv、中文正文和 20 个预览;本轮仅范围状态/交互及共享日历适配。range-calendar.css 加 hv- 前缀,原生 button 增加 w-full 等价块拉伸,Apache 声明沿用 third-party/HEROUI-LICENSE。Adobe 官方当日源文件仅作语义辅助审计,没有移植 React hook;与固定基线和待补能力分开记录,见 [DATE-04](migrations/DATE-04-range-foundation.md)。
|
||||
|
||||
@@ -906,3 +906,13 @@ Button/PopoverTrigger/Link/ToggleButtonGroup 源码及几何复核后,移除
|
||||
- 5174 浏览器验证月视图实际 252px、日期格 36px,ArrowRight+Enter 聚焦并选择 2026-10-25;年份层高 208px、scrollTop=1340、2026 年真实可见,选择 2027 年关闭并恢复 2027-10-24 日期焦点。周视图切两周后显示 10/18–31,下一页 11/1–14;十天窗口有十个可选日期及两个禁用前导补位。深浅色、同 SFC 高亮及四张 696px 满宽表无横溢出已验,截图 `/private/tmp/heroui-calendar-review.png`。
|
||||
- 最终两份 tarball 独立安装到 `/private/tmp/heroui-slider-consumer`,Calendar ESM/Node SSR/CSS、NodeNext/bundler 严格正反类型通过;单多选、实际泛型 SFC 模型/事件、部件必需属性及作用域插槽反例实际触发诊断。DateField/Select 类型与运行、ListBox 运行消费回归通过,无源码 alias。
|
||||
- 本轮为局部日期视图/键盘适配,复用现有接受值与 Intl 日期库,不宣称 Reka 已具备 week/day/YearPicker。没有自动逐像素、完整读屏、物理触屏、Nuxt 或全部日期族的完成结论。
|
||||
|
||||
## DATE-04 RangeCalendar 私有范围基建(2026-10-25)
|
||||
|
||||
- 从 main `5c4375a` 新建 feat/range-calendar-foundation,提取唯一 Calendar view/focus/year owner,范围接受值/锚点/预览/障碍及鼠标手势通过私有夹具接入。范围/差异和下一轮交接见 [DATE-04](migrations/DATE-04-range-foundation.md) / [DATE-05](migrations/DATE-05-range-calendar-prompt.md)。尚未公开 RangeCalendar 或正式文档页。
|
||||
- 新增 **28** 项行为/集成/实际 jsdom 水合 + **2** 项真正 node SSR;最终 `vitest run` 为 **75 文件 / 921 项通过**。既有 Calendar、DateField、Select 和全库测试保留。
|
||||
- `vue-tsc --noEmit`、`build:docs`(含组件/样式构建、文档 SSR)、全仓 Prettier 与 diff 空白检查通过。构建仍有已有文档大 chunk 提示;没有非法 CSS 警告。实际命令因 pnpm 11 的 deps 状态检查使用同一现有 store,未增加额外运行时 UI 库。
|
||||
- 最终两个 tarball 安装到 `/private/tmp/heroui-range-core-consumer`,无源码 paths/alias。Calendar/DateField/Select 的 Node ESM/SSR/CSS 脚本及 strict bundler/NodeNext 类型正反例全部通过。它证明共享重构未破坏现有发布接口,不证明未导出的 RangeCalendar 已完成公共消费验收。
|
||||
- 真实浏览器 5176 `?range-calendar-foundation`:36×36 日期按钮;拖动 10–15 日一次提交;两次点击首击只预览;受控边界拖动重复拒绝两次且接受值不变;键盘前进焦点;228px 日/年份网格对齐且当前年可见;拖过 disabled 月外日期不翻月,外部释放恢复已接受范围。
|
||||
- 浏览器实际发现并修复 capture 后微任务提前清手势、月外 disabled 指针仍触发导航、原生 button 未拉伸及旧 playground header/font 污染。jsdom 不能单独证明这些布局/原生派发行为。
|
||||
- 尚未实现触屏长按拖选;tap/click 与原生滚动路径保留。公开部件、20 正式预览、范围读屏提示/公告及产物类型留给下一批;范围字段/Picker/Time 桥接与颜色内核仍待集成人验证。未完成逐像素、完整读屏、真机、多浏览器或 Nuxt,不扩大本轮结论。
|
||||
|
||||
+2
-2
@@ -15,8 +15,8 @@
|
||||
"build:docs": "pnpm build && pnpm --filter @heroui-vue/docs build",
|
||||
"typecheck": "vue-tsc --noEmit",
|
||||
"test": "vitest run",
|
||||
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts tests/button-toggle.test.ts tests/m26-review.probe.test.ts tests/toolbar.test.ts tests/m29-review.probe.test.ts tests/m30-m32-review.probe.test.ts tests/pagination.test.ts tests/header.test.ts tests/input-otp.test.ts tests/number-field-foundation.test.ts tests/number-field.test.ts tests/slider-foundation.test.ts tests/slider.test.ts tests/collection-state.test.ts tests/collection-foundation.test.ts tests/list-box.test.ts tests/alert-dialog.test.ts tests/drawer.test.ts tests/m33-m34-review.probe.test.ts tests/m33-m34-lifecycle-review.probe.test.ts tests/m33-m34-coexist.test.ts tests/select.test.ts tests/date-value.test.ts tests/date-model.test.ts tests/date-foundation.test.ts tests/date-field.test.ts tests/date-field-demos.test.ts tests/toast.test.ts tests/table.test.ts tests/m35-m36-takeover.test.ts tests/m35-m36-review.probe.test.ts tests/m35-m36-review-2.probe.test.ts tests/m35-m36-review-3.probe.test.ts tests/m35-m36-review-4.probe.test.ts tests/m35-m36-review-5.probe.test.ts tests/m35-m36-hydration.test.ts tests/docs-shell.test.ts tests/calendar-view.test.ts tests/calendar.test.ts tests/calendar-demos.test.ts",
|
||||
"test:ssr": "vitest run tests/ssr.test.ts tests/input-otp-ssr.test.ts tests/slider-foundation-ssr.test.ts tests/slider-ssr.test.ts tests/collection-foundation-ssr.test.ts tests/list-box-ssr.test.ts tests/select-ssr.test.ts tests/date-foundation-ssr.test.ts tests/date-field-ssr.test.ts tests/m35-m36-ssr.test.ts tests/calendar-ssr.test.ts",
|
||||
"test:unit": "vitest run tests/choice-demos.test.ts tests/choice-fields.test.ts tests/fieldset-search-field.test.ts tests/components.test.ts tests/composition.test.ts tests/docs-search.test.ts tests/button-demos.test.ts tests/aligned-components.test.ts tests/surface-link-spinner.test.ts tests/close-button-avatar-skeleton.test.ts tests/separator-kbd-chip.test.ts tests/badge-alert.test.ts tests/input-group.test.ts tests/field-docs-textarea.test.ts tests/field-foundation.test.ts tests/typography-empty-breadcrumbs.test.ts tests/progress-meter.test.ts tests/disclosure-accordion.test.ts tests/overlay-foundation.test.ts tests/modal.test.ts tests/popover-tooltip.test.ts tests/overlay-demos.test.ts tests/scroll-tabs.test.ts tests/button-toggle.test.ts tests/m26-review.probe.test.ts tests/toolbar.test.ts tests/m29-review.probe.test.ts tests/m30-m32-review.probe.test.ts tests/pagination.test.ts tests/header.test.ts tests/input-otp.test.ts tests/number-field-foundation.test.ts tests/number-field.test.ts tests/slider-foundation.test.ts tests/slider.test.ts tests/collection-state.test.ts tests/collection-foundation.test.ts tests/list-box.test.ts tests/alert-dialog.test.ts tests/drawer.test.ts tests/m33-m34-review.probe.test.ts tests/m33-m34-lifecycle-review.probe.test.ts tests/m33-m34-coexist.test.ts tests/select.test.ts tests/date-value.test.ts tests/date-model.test.ts tests/date-foundation.test.ts tests/date-field.test.ts tests/date-field-demos.test.ts tests/toast.test.ts tests/table.test.ts tests/m35-m36-takeover.test.ts tests/m35-m36-review.probe.test.ts tests/m35-m36-review-2.probe.test.ts tests/m35-m36-review-3.probe.test.ts tests/m35-m36-review-4.probe.test.ts tests/m35-m36-review-5.probe.test.ts tests/m35-m36-hydration.test.ts tests/docs-shell.test.ts tests/calendar-view.test.ts tests/calendar.test.ts tests/calendar-demos.test.ts tests/range-calendar-foundation.test.ts",
|
||||
"test:ssr": "vitest run tests/ssr.test.ts tests/input-otp-ssr.test.ts tests/slider-foundation-ssr.test.ts tests/slider-ssr.test.ts tests/collection-foundation-ssr.test.ts tests/list-box-ssr.test.ts tests/select-ssr.test.ts tests/date-foundation-ssr.test.ts tests/date-field-ssr.test.ts tests/m35-m36-ssr.test.ts tests/calendar-ssr.test.ts tests/range-calendar-foundation-ssr.test.ts",
|
||||
"format": "prettier --check .",
|
||||
"format:fix": "prettier --write .",
|
||||
"dev:playground": "pnpm build && pnpm --filter @heroui-vue/playground dev"
|
||||
|
||||
@@ -0,0 +1,363 @@
|
||||
/* Adapted from HeroUI ce90ea3, Apache-2.0; see third-party/HEROUI-LICENSE. */
|
||||
/* =============================================================================
|
||||
* RangeCalendar Component Styles
|
||||
*
|
||||
* A compound component for contiguous date range selection.
|
||||
* Uses BEM naming convention: range-calendar, range-calendar__element, range-calendar--modifier
|
||||
* ============================================================================= */
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Base RangeCalendar Styles
|
||||
* -------------------------------------------------------------------------- */
|
||||
.hv-range-calendar {
|
||||
@apply w-63 max-w-63;
|
||||
|
||||
container-type: inline-size;
|
||||
}
|
||||
|
||||
/* Week view – visibleDuration={{ weeks: n }} */
|
||||
.hv-range-calendar--week-view {
|
||||
.hv-range-calendar__cell {
|
||||
/* Keep cells circular on the 7-column grid; only filled cells take space. */
|
||||
@apply aspect-square size-auto w-full place-self-center;
|
||||
}
|
||||
}
|
||||
|
||||
/* Day view – visibleDuration={{ days: n }} */
|
||||
.hv-range-calendar--day-view {
|
||||
.hv-range-calendar__cell {
|
||||
@apply aspect-square size-auto w-full place-self-center;
|
||||
}
|
||||
|
||||
/*
|
||||
* Isolate header and body into separate 7-column grids. With display:contents
|
||||
* on the root grid, fewer than 7 weekday headers flow into the same row as dates.
|
||||
*/
|
||||
.hv-range-calendar__grid {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.hv-range-calendar__grid-header {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, 1fr);
|
||||
@apply w-full;
|
||||
|
||||
& > tr {
|
||||
display: contents;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-range-calendar__grid-body {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, 1fr);
|
||||
@apply mt-1 w-full;
|
||||
|
||||
& > tr {
|
||||
display: contents;
|
||||
}
|
||||
|
||||
& > tr:first-child > td {
|
||||
@apply mt-0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* RangeCalendar Header
|
||||
* -------------------------------------------------------------------------- */
|
||||
.hv-range-calendar__header {
|
||||
@apply flex items-center justify-between px-0.5 pb-4;
|
||||
|
||||
&:has(.hv-calendar-year-picker__trigger[data-open="true"]) {
|
||||
.hv-range-calendar__nav-button {
|
||||
@apply pointer-events-none opacity-0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.hv-range-calendar__heading {
|
||||
@apply flex-1 text-sm font-medium;
|
||||
}
|
||||
|
||||
.hv-range-calendar__nav-button {
|
||||
@apply flex size-6 items-center justify-center rounded-xl text-accent-soft-foreground;
|
||||
|
||||
will-change: scale;
|
||||
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition:
|
||||
transform 250ms var(--ease-out),
|
||||
background-color 100ms var(--ease-out),
|
||||
box-shadow 100ms var(--ease-out),
|
||||
opacity 150ms var(--ease-out);
|
||||
@apply transform-gpu motion-reduce:transition-none;
|
||||
|
||||
cursor: var(--cursor-interactive);
|
||||
|
||||
/* Hover state – only on devices that support hover (avoids false triggers on touch) */
|
||||
@media (hover: hover) {
|
||||
&:hover,
|
||||
&[data-hovered="true"] {
|
||||
@apply bg-default text-accent-soft-foreground;
|
||||
}
|
||||
}
|
||||
|
||||
/* Pressed state */
|
||||
&:active,
|
||||
&[data-pressed="true"] {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
/* Focus state */
|
||||
&:focus-visible,
|
||||
&[data-focus-visible="true"] {
|
||||
@apply status-focused;
|
||||
}
|
||||
|
||||
/* Disabled state */
|
||||
&:disabled,
|
||||
&[data-disabled="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-range-calendar__nav-button-icon {
|
||||
@apply size-4 rtl:rotate-180;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* RangeCalendar Grid
|
||||
* -------------------------------------------------------------------------- */
|
||||
.hv-range-calendar__grid {
|
||||
/* Override table display with CSS Grid for easier customization */
|
||||
display: grid;
|
||||
grid-template-columns: repeat(7, 1fr);
|
||||
@apply w-full;
|
||||
|
||||
&[aria-readonly="true"] {
|
||||
.hv-range-calendar__cell {
|
||||
@apply pointer-events-none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.hv-range-calendar__grid-header {
|
||||
/* Grid header (thead) styles */
|
||||
display: contents;
|
||||
|
||||
& > tr {
|
||||
display: contents;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-range-calendar__grid-body {
|
||||
/* Grid body (tbody) styles */
|
||||
display: contents;
|
||||
|
||||
& > tr {
|
||||
display: contents;
|
||||
}
|
||||
|
||||
/* Add top spacing between header and first body row */
|
||||
& > tr:first-child > td {
|
||||
@apply mt-1;
|
||||
}
|
||||
}
|
||||
|
||||
.hv-range-calendar__grid-row {
|
||||
/* Use 'contents' so cells participate directly in grid */
|
||||
/* Note: This class can be used for custom row styling if needed */
|
||||
display: contents;
|
||||
}
|
||||
|
||||
.hv-range-calendar__header-cell {
|
||||
/* Header cell (th - weekday names) styles */
|
||||
@apply flex items-center justify-center pb-2 text-xs font-medium text-muted;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* RangeCalendar Cells
|
||||
* -------------------------------------------------------------------------- */
|
||||
.hv-range-calendar__cell {
|
||||
/* RAC uses a stretching block here; the Vue primitive is a native button. */
|
||||
@apply relative z-1 mx-0 my-[2px] w-full rounded-3xl p-0 outline-none;
|
||||
cursor: var(--cursor-interactive);
|
||||
|
||||
will-change: background-color, border-color;
|
||||
/**
|
||||
* Transitions
|
||||
* CRITICAL: motion-reduce must be AFTER transition for correct override specificity
|
||||
*/
|
||||
transition:
|
||||
box-shadow 100ms var(--ease-out),
|
||||
border-color 100ms var(--ease-out);
|
||||
@apply transform-gpu motion-reduce:transition-none;
|
||||
|
||||
/* Inner interactive circle/capsule (equivalent to React Aria "button-base") */
|
||||
.hv-range-calendar__cell-button {
|
||||
@apply flex aspect-square w-full items-center justify-center rounded-3xl text-sm font-medium text-foreground no-highlight;
|
||||
|
||||
will-change: scale;
|
||||
transition: scale 200ms var(--ease-out);
|
||||
@apply transform-gpu motion-reduce:transition-none;
|
||||
}
|
||||
|
||||
/* Focus state */
|
||||
&:focus-visible:not([data-focused]),
|
||||
&[data-focus-visible="true"] {
|
||||
@apply z-2;
|
||||
|
||||
.hv-range-calendar__cell-button {
|
||||
@apply status-focused;
|
||||
}
|
||||
}
|
||||
|
||||
/* Today indicator */
|
||||
&[data-today="true"] {
|
||||
.hv-range-calendar__cell-button {
|
||||
@apply bg-accent-soft text-accent-soft-foreground;
|
||||
}
|
||||
|
||||
@media (hover: hover) {
|
||||
&:hover:not([data-selected="true"]),
|
||||
&[data-hovered="true"]:not([data-selected="true"]) {
|
||||
.hv-range-calendar__cell-button {
|
||||
@apply bg-accent-soft-hover;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Range selected track (middle segment) */
|
||||
&[data-selected="true"]:not([data-outside-month="true"]) {
|
||||
@apply rounded-none bg-accent-soft;
|
||||
}
|
||||
|
||||
/* Round row boundaries so the range track looks continuous across weeks */
|
||||
&[data-selected="true"]:is(td:first-child > *, [aria-disabled] + td > *) {
|
||||
@apply rounded-ss-lg rounded-es-lg;
|
||||
&[data-selection-start="true"] {
|
||||
@apply rounded-ss-3xl rounded-es-3xl;
|
||||
}
|
||||
}
|
||||
|
||||
&[data-selected="true"]:is(td:last-child > *, td:has(+ [aria-disabled]) > *) {
|
||||
@apply rounded-se-lg rounded-ee-lg;
|
||||
&[data-selection-end="true"] {
|
||||
@apply rounded-se-3xl rounded-ee-3xl;
|
||||
}
|
||||
}
|
||||
|
||||
/* Range caps (start/end) */
|
||||
&[data-selection-start="true"]:not([data-outside-month="true"]),
|
||||
&[data-selection-end="true"]:not([data-outside-month="true"]) {
|
||||
@apply z-2;
|
||||
|
||||
.hv-range-calendar__cell-button {
|
||||
@apply bg-accent text-accent-foreground;
|
||||
}
|
||||
}
|
||||
|
||||
/* &[data-selection-start="true"]:has(+ [data-selection-end="true"]) {
|
||||
@apply rounded-full;
|
||||
} */
|
||||
|
||||
&[data-selection-start="true"]:not([data-outside-month="true"]) {
|
||||
@apply rounded-ss-3xl rounded-es-3xl;
|
||||
}
|
||||
|
||||
&[data-selection-end="true"]:not([data-outside-month="true"]) {
|
||||
@apply rounded-se-3xl rounded-ee-3xl;
|
||||
}
|
||||
|
||||
/* Pressed state */
|
||||
&:active,
|
||||
&[data-pressed="true"] {
|
||||
.hv-range-calendar__cell-button {
|
||||
scale: 0.9;
|
||||
}
|
||||
|
||||
&[data-selection-start="true"],
|
||||
&[data-selection-end="true"] {
|
||||
.hv-range-calendar__cell-button {
|
||||
@apply bg-accent-hover;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Hover state for non-selected days */
|
||||
@media (hover: hover) {
|
||||
&:hover:not([data-selected="true"]),
|
||||
&[data-hovered="true"]:not([data-selected="true"]) {
|
||||
.hv-range-calendar__cell-button {
|
||||
@apply bg-default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Outside month (previous/next month days) */
|
||||
&[data-outside-month="true"] {
|
||||
@apply text-muted opacity-50;
|
||||
}
|
||||
|
||||
&[data-selected="true"][data-outside-month="true"]:not(
|
||||
[data-selection-start="true"],
|
||||
[data-selection-end="true"]
|
||||
) {
|
||||
@apply bg-default/20;
|
||||
}
|
||||
|
||||
/* Unavailable dates */
|
||||
&[data-unavailable="true"] {
|
||||
@apply status-disabled;
|
||||
}
|
||||
|
||||
/* Disabled state */
|
||||
&:disabled:not([data-outside-month="true"]),
|
||||
&[data-disabled="true"]:not([data-outside-month="true"]) {
|
||||
@apply status-disabled;
|
||||
|
||||
text-decoration: line-through;
|
||||
}
|
||||
}
|
||||
|
||||
/* Outside-month cell followed by selected cell across adjacent table cells */
|
||||
.hv-range-calendar__grid-body
|
||||
td:has(> .hv-range-calendar__cell[data-outside-month="true"])
|
||||
+ td
|
||||
> .hv-range-calendar__cell[data-selected="true"] {
|
||||
@apply rounded-ss-lg rounded-es-lg;
|
||||
|
||||
&[data-outside-month="true"],
|
||||
&[data-selection-start="true"] {
|
||||
@apply rounded-ss-3xl rounded-es-3xl;
|
||||
}
|
||||
}
|
||||
|
||||
/* Selected cell followed by outside-month cell across adjacent table cells */
|
||||
.hv-range-calendar__grid-body
|
||||
td:has(> .hv-range-calendar__cell[data-selected="true"]):has(
|
||||
+ td > .hv-range-calendar__cell[data-outside-month="true"]
|
||||
)
|
||||
> .hv-range-calendar__cell[data-selected="true"] {
|
||||
@apply rounded-se-lg rounded-ee-lg;
|
||||
|
||||
&[data-outside-month="true"],
|
||||
&[data-selection-end="true"] {
|
||||
@apply rounded-se-3xl rounded-ee-3xl;
|
||||
}
|
||||
}
|
||||
|
||||
/* Cell indicator - small dot at bottom center of cell */
|
||||
.hv-range-calendar__cell-indicator {
|
||||
@apply absolute bottom-1 left-1/2 size-[3px] -translate-x-1/2 rounded-xs bg-muted;
|
||||
|
||||
/* Indicator color changes when cell is selected */
|
||||
[data-selected="true"] > & {
|
||||
@apply bg-accent-foreground;
|
||||
}
|
||||
}
|
||||
@@ -156,5 +156,7 @@
|
||||
@import "./components/date-field.css" layer(components);
|
||||
|
||||
@import "./components/calendar.css" layer(components);
|
||||
/* RangeCalendar styling staged for the private range interaction fixture. */
|
||||
@import "./components/range-calendar.css" layer(components);
|
||||
|
||||
@import "./components/calendar-year-picker.css" layer(components);
|
||||
|
||||
@@ -1,46 +1,20 @@
|
||||
<script setup lang="ts" generic="M extends CalendarSelectionMode = 'single'">
|
||||
import { computed, getCurrentInstance, useAttrs } from "vue";
|
||||
import {
|
||||
computed,
|
||||
getCurrentInstance,
|
||||
nextTick,
|
||||
onMounted,
|
||||
onBeforeUnmount,
|
||||
provide,
|
||||
shallowRef,
|
||||
useAttrs,
|
||||
useId,
|
||||
watch,
|
||||
} from "vue";
|
||||
import {
|
||||
CalendarDate,
|
||||
GregorianCalendar,
|
||||
getLocalTimeZone,
|
||||
today,
|
||||
toCalendar,
|
||||
toCalendarDate,
|
||||
isSameDay,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
import { useChoiceValue } from "../choice/shared";
|
||||
import {
|
||||
copyDateValue,
|
||||
copyDateValues,
|
||||
dateForLocale,
|
||||
dateValueKey,
|
||||
} from "../date/value";
|
||||
import {
|
||||
calendarRange,
|
||||
calendarDuration,
|
||||
calendarHeading,
|
||||
} from "../date/calendar";
|
||||
import { useInheritedDisabled } from "../field/disabled";
|
||||
import { useConfig } from "../../providers/context";
|
||||
import {
|
||||
calendarKey,
|
||||
type CalendarModel,
|
||||
type CalendarOptions,
|
||||
type CalendarSelectionMode,
|
||||
type CalendarContext,
|
||||
import { copyDateValue, copyDateValues } from "../date/value";
|
||||
import { calendarHeading } from "../date/calendar";
|
||||
import { useCalendarView } from "./view";
|
||||
import type {
|
||||
CalendarModel,
|
||||
CalendarOptions,
|
||||
CalendarSelectionMode,
|
||||
} from "./context";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const props = defineProps<CalendarOptions<M>>();
|
||||
@@ -64,24 +38,7 @@ defineSlots<{
|
||||
}) => unknown;
|
||||
}>();
|
||||
const attrs = useAttrs(),
|
||||
instance = getCurrentInstance()!,
|
||||
config = useConfig();
|
||||
const root = shallowRef<HTMLElement>(),
|
||||
trigger = shallowRef<HTMLElement>();
|
||||
const headingId = `hv-calendar-${useId()}-heading`;
|
||||
const locale = computed(() => props.locale ?? config?.locale.value ?? "en-US");
|
||||
const dir = computed(() => props.dir ?? config?.dir.value ?? "ltr");
|
||||
const timeZone = computed(() => props.timeZone ?? getLocalTimeZone());
|
||||
const disabled = useInheritedDisabled(() => props.isDisabled || props.disabled);
|
||||
const readOnly = computed(() => !!props.isReadOnly);
|
||||
const multiple = computed(() => props.selectionMode === "multiple");
|
||||
const invalid = computed(() => !!props.isInvalid);
|
||||
const options = computed(() => ({
|
||||
locale: locale.value,
|
||||
firstDayOfWeek: props.firstDayOfWeek,
|
||||
visibleDuration: props.visibleDuration,
|
||||
weeksInMonth: props.weeksInMonth,
|
||||
}));
|
||||
instance = getCurrentInstance()!;
|
||||
type Value = DateValue | DateValue[] | null;
|
||||
const copy = (value: Value | undefined): Value =>
|
||||
Array.isArray(value) ? copyDateValues(value) : copyDateValue(value ?? null);
|
||||
@@ -102,95 +59,43 @@ const selectedValues = computed(() => {
|
||||
const value = model.value.value;
|
||||
return Array.isArray(value) ? value : value ? [value] : [];
|
||||
});
|
||||
const initial = copyDateValue(
|
||||
props.defaultFocusedValue ?? selectedValues.value[0] ?? today(timeZone.value),
|
||||
);
|
||||
const focusModel = useChoiceValue<DateValue>(
|
||||
() => copyDateValue(props.focusedValue ?? initial),
|
||||
() => copyDateValue(initial),
|
||||
["focusedValue", "focused-value"],
|
||||
(value) => {
|
||||
emit("update:focusedValue", value.copy());
|
||||
emit("focusChange", value.copy());
|
||||
},
|
||||
);
|
||||
const focus = computed(() =>
|
||||
toCalendarDate(dateForLocale(focusModel.value.value, locale.value)),
|
||||
);
|
||||
const min = computed(() =>
|
||||
toCalendarDate(
|
||||
dateForLocale(props.minValue ?? new CalendarDate(1900, 1, 1), locale.value),
|
||||
),
|
||||
);
|
||||
const max = computed(() =>
|
||||
toCalendarDate(
|
||||
dateForLocale(
|
||||
props.maxValue ?? new CalendarDate(2099, 12, 31),
|
||||
locale.value,
|
||||
),
|
||||
),
|
||||
);
|
||||
function aligned(date: typeof focus.value) {
|
||||
const { unit, count } = calendarDuration(props.visibleDuration);
|
||||
const alignment = props.selectionAlignment ?? "center";
|
||||
const amount =
|
||||
alignment === "start"
|
||||
? 0
|
||||
: alignment === "end"
|
||||
? count - 1
|
||||
: Math.floor((count - 1) / 2);
|
||||
return date.subtract({ [unit]: amount });
|
||||
}
|
||||
const anchor = shallowRef(aligned(focus.value));
|
||||
const visible = computed(() => calendarRange(anchor.value, options.value));
|
||||
const yearModel = useChoiceValue(
|
||||
() => !!props.isYearPickerOpen,
|
||||
() => !!props.defaultYearPickerOpen,
|
||||
["isYearPickerOpen", "is-year-picker-open"],
|
||||
(value) => {
|
||||
emit("update:isYearPickerOpen", value);
|
||||
emit("yearPickerOpenChange", value);
|
||||
},
|
||||
);
|
||||
const yearOpen = computed(() => yearModel.value.value);
|
||||
function disabledDay(value: DateValue) {
|
||||
return (
|
||||
disabled.value ||
|
||||
toCalendarDate(value).compare(min.value) < 0 ||
|
||||
toCalendarDate(value).compare(max.value) > 0 ||
|
||||
!!props.isDateDisabled?.(value.copy())
|
||||
);
|
||||
}
|
||||
const tabStop = computed(() => {
|
||||
const range = visible.value;
|
||||
if (
|
||||
!disabledDay(focus.value) &&
|
||||
focus.value.compare(range.start) >= 0 &&
|
||||
focus.value.compare(range.end) <= 0
|
||||
)
|
||||
return focus.value;
|
||||
let date = range.start;
|
||||
while (date.compare(range.end) <= 0) {
|
||||
if (!disabledDay(date)) return date;
|
||||
const next = date.add({ days: 1 });
|
||||
if (isSameDay(date, next)) break;
|
||||
date = next;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
const unavailable = (date: DateValue) =>
|
||||
!!props.isDateUnavailable?.(date.copy());
|
||||
const selected = (date: DateValue) =>
|
||||
selectedValues.value.some((value) => isSameDay(value, date));
|
||||
const view = useCalendarView(
|
||||
props,
|
||||
{
|
||||
dates: selectedValues,
|
||||
selected,
|
||||
request,
|
||||
unavailable: (date) => !!props.isDateUnavailable?.(date.copy()),
|
||||
multiple: () => props.selectionMode === "multiple",
|
||||
},
|
||||
emit,
|
||||
);
|
||||
const {
|
||||
root,
|
||||
focus,
|
||||
anchor,
|
||||
options,
|
||||
disabled,
|
||||
readOnly,
|
||||
invalid,
|
||||
dir,
|
||||
yearOpen,
|
||||
visible,
|
||||
tabStop,
|
||||
focusDate,
|
||||
} = view;
|
||||
function request(value: DateValue) {
|
||||
if (disabledDay(value) || unavailable(value) || readOnly.value) return;
|
||||
if (view.disabledDay(value) || view.unavailable(value) || view.readOnly.value)
|
||||
return;
|
||||
const fallback = Array.isArray(props.defaultValue)
|
||||
? props.defaultValue[0]
|
||||
: props.defaultValue;
|
||||
const original =
|
||||
selectedValues.value[0] ??
|
||||
fallback ??
|
||||
toCalendarDate(toCalendar(focus.value, new GregorianCalendar()));
|
||||
toCalendarDate(toCalendar(view.focus.value, new GregorianCalendar()));
|
||||
// Preserve the public model's calendar, date class, time and zone.
|
||||
const day = toCalendar(value, original.calendar);
|
||||
const next = original.set({
|
||||
@@ -208,148 +113,6 @@ function request(value: DateValue) {
|
||||
);
|
||||
} else if (!selected(value)) model.request(next.copy());
|
||||
}
|
||||
function focusDate(date: DateValue, moveDOM = false) {
|
||||
if (disabledDay(date)) return;
|
||||
const original = focusModel.value.value;
|
||||
const converted = toCalendar(date, original.calendar);
|
||||
if (!isSameDay(original, converted)) focusModel.request(converted.copy());
|
||||
const active = root.value?.ownerDocument.activeElement;
|
||||
const restoreControlledFocus =
|
||||
!!active &&
|
||||
root.value?.contains(active) &&
|
||||
active.getAttribute("data-slot") === "calendar-cell";
|
||||
if (moveDOM || restoreControlledFocus)
|
||||
void nextTick(() => {
|
||||
if (yearOpen.value) return;
|
||||
const iso = (tabStop.value ?? focus.value).toString();
|
||||
root.value
|
||||
?.querySelector<HTMLElement>(
|
||||
`[data-slot="calendar-cell"][data-date="${iso}"]:not([data-outside-month])`,
|
||||
)
|
||||
?.focus();
|
||||
});
|
||||
}
|
||||
watch(
|
||||
() => dateValueKey(focus.value),
|
||||
() => {
|
||||
const active = root.value?.ownerDocument.activeElement;
|
||||
const retainFocus =
|
||||
!!active &&
|
||||
root.value?.contains(active) &&
|
||||
active.getAttribute("data-slot") === "calendar-cell";
|
||||
if (
|
||||
focus.value.compare(visible.value.start) < 0 ||
|
||||
focus.value.compare(visible.value.end) > 0
|
||||
)
|
||||
anchor.value = aligned(focus.value);
|
||||
if (retainFocus)
|
||||
void nextTick(() => {
|
||||
if (!yearOpen.value)
|
||||
root.value
|
||||
?.querySelector<HTMLElement>(
|
||||
`[data-slot="calendar-cell"][tabindex="0"]`,
|
||||
)
|
||||
?.focus();
|
||||
});
|
||||
},
|
||||
{ flush: "sync" },
|
||||
);
|
||||
watch(
|
||||
[locale, () => props.visibleDuration, () => props.firstDayOfWeek],
|
||||
() => {
|
||||
anchor.value = aligned(focus.value);
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
watch(
|
||||
() => selectedValues.value.map(dateValueKey).join("|"),
|
||||
() => {
|
||||
if (
|
||||
!has("focusedValue") &&
|
||||
!has("focused-value") &&
|
||||
selectedValues.value[0]
|
||||
)
|
||||
focusDate(selectedValues.value[0]);
|
||||
},
|
||||
);
|
||||
function pageStep(direction: -1 | 1) {
|
||||
const { unit, count } = calendarDuration(props.visibleDuration);
|
||||
return { [unit]: direction * (props.pageBehavior === "single" ? 1 : count) };
|
||||
}
|
||||
function pageDisabled(direction: -1 | 1) {
|
||||
if (disabled.value || yearOpen.value) return true;
|
||||
const range = calendarRange(
|
||||
anchor.value.add(pageStep(direction)),
|
||||
options.value,
|
||||
);
|
||||
return range.end.compare(min.value) < 0 || range.start.compare(max.value) > 0;
|
||||
}
|
||||
let pageRevision = 0;
|
||||
onBeforeUnmount(() => {
|
||||
pageRevision++;
|
||||
});
|
||||
function page(direction: -1 | 1) {
|
||||
if (pageDisabled(direction)) return;
|
||||
const nextAnchor = anchor.value.add(pageStep(direction));
|
||||
const range = calendarRange(nextAnchor, options.value);
|
||||
let date = focus.value.add(pageStep(direction));
|
||||
if (date.compare(min.value) < 0) date = min.value;
|
||||
if (date.compare(max.value) > 0) date = max.value;
|
||||
// Disabled target days must not make an otherwise navigable month inert.
|
||||
if (disabledDay(date)) {
|
||||
let candidate = range.start;
|
||||
while (candidate.compare(range.end) <= 0 && disabledDay(candidate)) {
|
||||
const next = candidate.add({ days: 1 });
|
||||
if (isSameDay(candidate, next)) return;
|
||||
candidate = next;
|
||||
}
|
||||
if (candidate.compare(range.end) > 0) return;
|
||||
date = candidate;
|
||||
}
|
||||
focusDate(date);
|
||||
const revision = ++pageRevision;
|
||||
void nextTick(() => {
|
||||
if (revision === pageRevision && isSameDay(focus.value, date))
|
||||
anchor.value = nextAnchor;
|
||||
});
|
||||
}
|
||||
function setYearOpen(value: boolean, restore = false) {
|
||||
if (disabled.value) return;
|
||||
yearModel.request(value);
|
||||
if (!value && restore)
|
||||
void nextTick(() => {
|
||||
if (!yearOpen.value) trigger.value?.focus();
|
||||
});
|
||||
}
|
||||
provide(calendarKey, {
|
||||
root,
|
||||
trigger,
|
||||
focus,
|
||||
anchor,
|
||||
options,
|
||||
min,
|
||||
max,
|
||||
disabled,
|
||||
tabStop,
|
||||
readOnly,
|
||||
multiple,
|
||||
invalid,
|
||||
dir,
|
||||
timeZone,
|
||||
yearOpen,
|
||||
headingId,
|
||||
selected,
|
||||
disabledDay,
|
||||
unavailable,
|
||||
request,
|
||||
focusDate,
|
||||
page,
|
||||
pageDisabled,
|
||||
setYearOpen,
|
||||
} satisfies CalendarContext);
|
||||
onMounted(() => {
|
||||
if (props.autoFocus && tabStop.value) focusDate(tabStop.value, true);
|
||||
});
|
||||
defineExpose({
|
||||
get element() {
|
||||
return root.value;
|
||||
|
||||
@@ -54,8 +54,32 @@ export interface CalendarCellState {
|
||||
isFocusVisible: boolean;
|
||||
isHovered: boolean;
|
||||
isPressed: boolean;
|
||||
isSelectionStart: boolean;
|
||||
isSelectionEnd: boolean;
|
||||
isInvalid: boolean;
|
||||
}
|
||||
/** Private gesture bridge. The selection owner, not individual cells, owns drafts. */
|
||||
export interface CalendarRangeInteraction {
|
||||
focusTarget: (date: DateValue) => DateValue;
|
||||
state: (
|
||||
date: DateValue,
|
||||
) => Pick<
|
||||
CalendarCellState,
|
||||
"isSelectionStart" | "isSelectionEnd" | "isInvalid"
|
||||
>;
|
||||
activate: (
|
||||
date: DateValue,
|
||||
source: "keyboard" | "virtual",
|
||||
event?: Event,
|
||||
) => void;
|
||||
pointerDown: (date: DateValue, event: PointerEvent) => void;
|
||||
pointerEnter: (date: DateValue, event: PointerEvent) => void;
|
||||
pointerUp: (date: DateValue, event: PointerEvent) => void;
|
||||
click: (date: DateValue, event: MouseEvent) => void;
|
||||
cancel: () => boolean;
|
||||
}
|
||||
export interface CalendarContext {
|
||||
prefix: "calendar" | "range-calendar";
|
||||
root: ShallowRef<HTMLElement | undefined>;
|
||||
trigger: ShallowRef<HTMLElement | undefined>;
|
||||
focus: ComputedRef<CalendarDate>;
|
||||
@@ -80,6 +104,7 @@ export interface CalendarContext {
|
||||
page: (direction: -1 | 1) => void;
|
||||
pageDisabled: (direction: -1 | 1) => boolean;
|
||||
setYearOpen: (value: boolean, restore?: boolean) => void;
|
||||
range?: CalendarRangeInteraction;
|
||||
}
|
||||
export const calendarKey: InjectionKey<CalendarContext> = Symbol("hv-calendar");
|
||||
export function useCalendar() {
|
||||
|
||||
@@ -73,14 +73,14 @@ function staticPart(
|
||||
inheritAttrs: false,
|
||||
props: { as: { type: String, default: tag } },
|
||||
setup(props, { attrs, slots }) {
|
||||
useCalendar();
|
||||
const ctx = useCalendar();
|
||||
return () =>
|
||||
h(
|
||||
props.as,
|
||||
mergeProps(
|
||||
{
|
||||
class: className,
|
||||
"data-slot": slot,
|
||||
class: className.replace("hv-calendar__", `hv-${ctx.prefix}__`),
|
||||
"data-slot": slot.replace("calendar-", `${ctx.prefix}-`),
|
||||
"aria-hidden":
|
||||
slot === "calendar-cell-indicator" ? "true" : undefined,
|
||||
},
|
||||
@@ -126,8 +126,8 @@ export const CalendarHeading = defineComponent({
|
||||
mergeProps(
|
||||
{
|
||||
id,
|
||||
class: "hv-calendar__heading",
|
||||
"data-slot": "calendar-heading",
|
||||
class: `hv-${ctx.prefix}__heading`,
|
||||
"data-slot": `${ctx.prefix}-heading`,
|
||||
"aria-live": "polite",
|
||||
"aria-atomic": "true",
|
||||
},
|
||||
@@ -162,12 +162,12 @@ export const CalendarNavButton = defineComponent({
|
||||
mergeProps(
|
||||
{
|
||||
type: "button",
|
||||
class: "hv-calendar__nav-button",
|
||||
class: `hv-${ctx.prefix}__nav-button`,
|
||||
"aria-label": direction === -1 ? "Previous" : "Next",
|
||||
},
|
||||
attrs,
|
||||
{
|
||||
"data-slot": "calendar-nav-button",
|
||||
"data-slot": `${ctx.prefix}-nav-button`,
|
||||
disabled,
|
||||
tabindex: ctx.yearOpen.value ? -1 : attrs.tabindex,
|
||||
"data-disabled": disabled || undefined,
|
||||
@@ -176,7 +176,12 @@ export const CalendarNavButton = defineComponent({
|
||||
},
|
||||
},
|
||||
),
|
||||
slots.default?.() ?? [calendarChevron(direction === -1)],
|
||||
slots.default?.() ?? [
|
||||
calendarChevron(
|
||||
direction === -1,
|
||||
`hv-${ctx.prefix}__nav-button-icon`,
|
||||
),
|
||||
],
|
||||
);
|
||||
};
|
||||
},
|
||||
@@ -207,7 +212,7 @@ export const CalendarGrid = defineComponent({
|
||||
"table",
|
||||
mergeProps(
|
||||
{
|
||||
class: "hv-calendar__grid",
|
||||
class: `hv-${ctx.prefix}__grid`,
|
||||
role: "grid",
|
||||
"aria-label": calendarHeading(
|
||||
ctx.anchor.value,
|
||||
@@ -220,7 +225,7 @@ export const CalendarGrid = defineComponent({
|
||||
},
|
||||
attrs,
|
||||
{
|
||||
"data-slot": "calendar-grid",
|
||||
"data-slot": `${ctx.prefix}-grid`,
|
||||
"aria-hidden": ctx.yearOpen.value || undefined,
|
||||
inert: ctx.yearOpen.value ? "" : undefined,
|
||||
},
|
||||
@@ -236,14 +241,15 @@ export const CalendarGridHeader = defineComponent({
|
||||
default?: (state: { day: string; index: number }) => VNodeChild;
|
||||
}>,
|
||||
setup(_props, { attrs, slots }) {
|
||||
const ctx = useCalendar();
|
||||
const grid = useCalendarGrid();
|
||||
return () =>
|
||||
h(
|
||||
"thead",
|
||||
mergeProps(
|
||||
{
|
||||
class: "hv-calendar__grid-header",
|
||||
"data-slot": "calendar-grid-header",
|
||||
class: `hv-${ctx.prefix}__grid-header`,
|
||||
"data-slot": `${ctx.prefix}-grid-header`,
|
||||
},
|
||||
attrs,
|
||||
),
|
||||
@@ -267,21 +273,22 @@ export const CalendarGridBody = defineComponent({
|
||||
default?: (state: { date: DateValue }) => VNodeChild;
|
||||
}>,
|
||||
setup(_props, { attrs, slots }) {
|
||||
const ctx = useCalendar();
|
||||
const grid = useCalendarGrid();
|
||||
return () =>
|
||||
h(
|
||||
"tbody",
|
||||
mergeProps(
|
||||
{
|
||||
class: "hv-calendar__grid-body",
|
||||
"data-slot": "calendar-grid-body",
|
||||
class: `hv-${ctx.prefix}__grid-body`,
|
||||
"data-slot": `${ctx.prefix}-grid-body`,
|
||||
},
|
||||
attrs,
|
||||
),
|
||||
grid.value.rows.map((row, index) =>
|
||||
h(
|
||||
"tr",
|
||||
{ key: index, class: "hv-calendar__grid-row" },
|
||||
{ key: index, class: `hv-${ctx.prefix}__grid-row` },
|
||||
row.map((date, index) =>
|
||||
date
|
||||
? (slots.default?.({ date: date.copy() }) ??
|
||||
@@ -334,6 +341,10 @@ export const CalendarCell = defineComponent({
|
||||
isHovered: hovered.value,
|
||||
isPressed: pressed.value,
|
||||
isFocusVisible: focusVisible.value,
|
||||
isSelectionStart: false,
|
||||
isSelectionEnd: false,
|
||||
isInvalid: ctx.invalid.value && ctx.selected(props.date),
|
||||
...ctx.range?.state(props.date),
|
||||
};
|
||||
});
|
||||
watch(
|
||||
@@ -357,6 +368,11 @@ export const CalendarCell = defineComponent({
|
||||
event.altKey
|
||||
)
|
||||
return;
|
||||
if (event.key === "Escape" && ctx.range?.cancel()) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
const date = props.date;
|
||||
const sign = ctx.dir.value === "rtl" ? -1 : 1;
|
||||
let target: DateValue;
|
||||
@@ -404,7 +420,8 @@ export const CalendarCell = defineComponent({
|
||||
case " ":
|
||||
event.preventDefault();
|
||||
pressed.value = true;
|
||||
ctx.request(date);
|
||||
if (ctx.range) ctx.range.activate(date, "keyboard", event);
|
||||
else ctx.request(date);
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
@@ -413,6 +430,7 @@ export const CalendarCell = defineComponent({
|
||||
event.stopPropagation();
|
||||
if (target.compare(ctx.min.value) < 0) target = ctx.min.value;
|
||||
if (target.compare(ctx.max.value) > 0) target = ctx.max.value;
|
||||
target = ctx.range?.focusTarget(target) ?? target;
|
||||
// Bounds are finite and calendar arithmetic may saturate at year limits.
|
||||
while (
|
||||
target.compare(ctx.min.value) >= 0 &&
|
||||
@@ -422,7 +440,8 @@ export const CalendarCell = defineComponent({
|
||||
ctx.focusDate(target, true);
|
||||
return;
|
||||
}
|
||||
const next = target.add({ days: step });
|
||||
const candidate = target.add({ days: step });
|
||||
const next = ctx.range?.focusTarget(candidate) ?? candidate;
|
||||
if (isSameDay(next, target)) return;
|
||||
target = next;
|
||||
}
|
||||
@@ -438,6 +457,7 @@ export const CalendarCell = defineComponent({
|
||||
{
|
||||
role: "gridcell",
|
||||
"aria-selected": value.isSelected,
|
||||
"aria-invalid": value.isInvalid || undefined,
|
||||
"aria-hidden": value.isOutsideMonth || undefined,
|
||||
"aria-disabled": value.isDisabled || value.isUnavailable || undefined,
|
||||
},
|
||||
@@ -447,7 +467,7 @@ export const CalendarCell = defineComponent({
|
||||
mergeProps(
|
||||
{
|
||||
type: "button",
|
||||
class: "hv-calendar__cell",
|
||||
class: `hv-${ctx.prefix}__cell`,
|
||||
tabindex:
|
||||
!ctx.yearOpen.value &&
|
||||
!value.isDisabled &&
|
||||
@@ -463,10 +483,14 @@ export const CalendarCell = defineComponent({
|
||||
ref: (node: unknown) => {
|
||||
element = node as HTMLButtonElement | undefined;
|
||||
},
|
||||
"data-slot": "calendar-cell",
|
||||
"data-slot": `${ctx.prefix}-cell`,
|
||||
"data-date": props.date.toString(),
|
||||
disabled: value.isDisabled,
|
||||
"data-selected": value.isSelected || undefined,
|
||||
"data-selection-start": value.isSelectionStart || undefined,
|
||||
"data-selection-end": value.isSelectionEnd || undefined,
|
||||
"data-invalid": value.isInvalid || undefined,
|
||||
"aria-invalid": value.isInvalid || undefined,
|
||||
"data-today": value.isToday || undefined,
|
||||
"data-disabled": value.isDisabled || undefined,
|
||||
"data-unavailable": value.isUnavailable || undefined,
|
||||
@@ -475,6 +499,11 @@ export const CalendarCell = defineComponent({
|
||||
value.isDisabled || value.isUnavailable || undefined,
|
||||
onKeydown: keydown,
|
||||
onClick: (event: MouseEvent) => {
|
||||
if (ctx.range) {
|
||||
if (value.isDisabled || ctx.yearOpen.value) return;
|
||||
ctx.range.click(props.date, event);
|
||||
return;
|
||||
}
|
||||
if (
|
||||
!event.defaultPrevented &&
|
||||
!ctx.yearOpen.value &&
|
||||
@@ -488,14 +517,19 @@ export const CalendarCell = defineComponent({
|
||||
"data-focus-visible": focusVisible.value || undefined,
|
||||
"data-hovered": hovered.value || undefined,
|
||||
"data-pressed": pressed.value || undefined,
|
||||
onPointerenter: () => {
|
||||
if (!value.isDisabled) hovered.value = true;
|
||||
onPointerenter: (event: PointerEvent) => {
|
||||
if (!event.defaultPrevented && !value.isDisabled)
|
||||
hovered.value = true;
|
||||
if (!value.isDisabled && !ctx.yearOpen.value)
|
||||
ctx.range?.pointerEnter(props.date, event);
|
||||
},
|
||||
onPointerleave: () => {
|
||||
hovered.value = false;
|
||||
pressed.value = false;
|
||||
},
|
||||
onPointerdown: (event: PointerEvent) => {
|
||||
if (!value.isDisabled && !ctx.yearOpen.value)
|
||||
ctx.range?.pointerDown(props.date, event);
|
||||
if (
|
||||
!event.defaultPrevented &&
|
||||
!value.isDisabled &&
|
||||
@@ -503,7 +537,9 @@ export const CalendarCell = defineComponent({
|
||||
)
|
||||
pressed.value = true;
|
||||
},
|
||||
onPointerup: () => {
|
||||
onPointerup: (event: PointerEvent) => {
|
||||
if (!value.isDisabled && !ctx.yearOpen.value)
|
||||
ctx.range?.pointerUp(props.date, event);
|
||||
pressed.value = false;
|
||||
},
|
||||
onKeyup: () => {
|
||||
@@ -524,7 +560,20 @@ export const CalendarCell = defineComponent({
|
||||
},
|
||||
},
|
||||
),
|
||||
slots.default?.(value) ?? value.formattedDate,
|
||||
ctx.range
|
||||
? h(
|
||||
"span",
|
||||
{
|
||||
class: `hv-${ctx.prefix}__cell-button`,
|
||||
"data-slot": `${ctx.prefix}-cell-button`,
|
||||
"data-selected":
|
||||
value.isSelectionStart ||
|
||||
value.isSelectionEnd ||
|
||||
undefined,
|
||||
},
|
||||
slots.default?.(value) ?? value.formattedDate,
|
||||
)
|
||||
: (slots.default?.(value) ?? value.formattedDate),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
@@ -0,0 +1,334 @@
|
||||
import {
|
||||
computed,
|
||||
getCurrentInstance,
|
||||
nextTick,
|
||||
onMounted,
|
||||
onBeforeUnmount,
|
||||
provide,
|
||||
shallowRef,
|
||||
useId,
|
||||
watch,
|
||||
type ComputedRef,
|
||||
} from "vue";
|
||||
import {
|
||||
CalendarDate,
|
||||
getLocalTimeZone,
|
||||
today,
|
||||
toCalendarDate,
|
||||
toCalendar,
|
||||
isSameDay,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
import { useChoiceValue } from "../choice/shared";
|
||||
import { copyDateValue, dateForLocale, dateValueKey } from "../date/value";
|
||||
import {
|
||||
calendarRange,
|
||||
calendarDuration,
|
||||
type CalendarViewOptions,
|
||||
} from "../date/calendar";
|
||||
import { useInheritedDisabled } from "../field/disabled";
|
||||
import { useConfig } from "../../providers/context";
|
||||
import {
|
||||
calendarKey,
|
||||
type CalendarContext,
|
||||
type CalendarOptions,
|
||||
type CalendarRangeInteraction,
|
||||
} from "./context";
|
||||
|
||||
export type CalendarViewProps = Omit<
|
||||
CalendarOptions<"single">,
|
||||
| "modelValue"
|
||||
| "value"
|
||||
| "defaultValue"
|
||||
| "selectionMode"
|
||||
| "isDateUnavailable"
|
||||
>;
|
||||
export interface CalendarSelectionAdapter {
|
||||
dates: ComputedRef<DateValue[]>;
|
||||
selected: (date: DateValue) => boolean;
|
||||
request: (date: DateValue) => void;
|
||||
unavailable?: (date: DateValue) => boolean;
|
||||
multiple?: () => boolean;
|
||||
invalid?: () => boolean;
|
||||
disabledDay?: (date: DateValue) => boolean;
|
||||
range?: CalendarRangeInteraction;
|
||||
followSelected?: boolean;
|
||||
alignment?: (
|
||||
date: CalendarDate,
|
||||
options: CalendarViewOptions,
|
||||
) => "start" | "center" | "end";
|
||||
}
|
||||
type ViewEmit = {
|
||||
(event: "yearPickerOpenChange", value: boolean): void;
|
||||
(event: "update:focusedValue", value: DateValue): void;
|
||||
(event: "focusChange", value: DateValue): void;
|
||||
(event: "update:isYearPickerOpen", value: boolean): void;
|
||||
};
|
||||
/** One view/focus/year owner for Calendar and RangeCalendar. Private implementation API. */
|
||||
export function useCalendarView(
|
||||
props: CalendarViewProps,
|
||||
selection: CalendarSelectionAdapter,
|
||||
emit: ViewEmit,
|
||||
prefix: "calendar" | "range-calendar" = "calendar",
|
||||
) {
|
||||
const instance = getCurrentInstance()!,
|
||||
config = useConfig();
|
||||
const has = (key: string) => Object.hasOwn(instance.vnode.props ?? {}, key);
|
||||
const root = shallowRef<HTMLElement>(),
|
||||
trigger = shallowRef<HTMLElement>();
|
||||
const headingId = `hv-calendar-${useId()}-heading`;
|
||||
const locale = computed(
|
||||
() => props.locale ?? config?.locale.value ?? "en-US",
|
||||
);
|
||||
const dir = computed(() => props.dir ?? config?.dir.value ?? "ltr");
|
||||
const timeZone = computed(() => props.timeZone ?? getLocalTimeZone());
|
||||
const disabled = useInheritedDisabled(
|
||||
() => props.isDisabled || props.disabled,
|
||||
);
|
||||
const readOnly = computed(() => !!props.isReadOnly);
|
||||
const multiple = computed(() => selection.multiple?.() ?? false);
|
||||
const invalid = computed(() => !!props.isInvalid || !!selection.invalid?.());
|
||||
const options = computed(() => ({
|
||||
locale: locale.value,
|
||||
firstDayOfWeek: props.firstDayOfWeek,
|
||||
visibleDuration: props.visibleDuration,
|
||||
weeksInMonth: props.weeksInMonth,
|
||||
}));
|
||||
const initial = copyDateValue(
|
||||
props.defaultFocusedValue ??
|
||||
selection.dates.value[0] ??
|
||||
today(timeZone.value),
|
||||
);
|
||||
const focusModel = useChoiceValue<DateValue>(
|
||||
() => copyDateValue(props.focusedValue ?? initial),
|
||||
() => copyDateValue(initial),
|
||||
["focusedValue", "focused-value"],
|
||||
(value) => {
|
||||
emit("update:focusedValue", value.copy());
|
||||
emit("focusChange", value.copy());
|
||||
},
|
||||
);
|
||||
const focus = computed(() =>
|
||||
toCalendarDate(dateForLocale(focusModel.value.value, locale.value)),
|
||||
);
|
||||
const min = computed(() =>
|
||||
toCalendarDate(
|
||||
dateForLocale(
|
||||
props.minValue ?? new CalendarDate(1900, 1, 1),
|
||||
locale.value,
|
||||
),
|
||||
),
|
||||
);
|
||||
const max = computed(() =>
|
||||
toCalendarDate(
|
||||
dateForLocale(
|
||||
props.maxValue ?? new CalendarDate(2099, 12, 31),
|
||||
locale.value,
|
||||
),
|
||||
),
|
||||
);
|
||||
function aligned(date: typeof focus.value) {
|
||||
const { unit, count } = calendarDuration(props.visibleDuration);
|
||||
const alignment =
|
||||
props.selectionAlignment ??
|
||||
selection.alignment?.(date, options.value) ??
|
||||
"center";
|
||||
const amount =
|
||||
alignment === "start"
|
||||
? 0
|
||||
: alignment === "end"
|
||||
? count - 1
|
||||
: Math.floor((count - 1) / 2);
|
||||
return date.subtract({ [unit]: amount });
|
||||
}
|
||||
const anchor = shallowRef(aligned(focus.value));
|
||||
const visible = computed(() => calendarRange(anchor.value, options.value));
|
||||
const yearModel = useChoiceValue(
|
||||
() => !!props.isYearPickerOpen,
|
||||
() => !!props.defaultYearPickerOpen,
|
||||
["isYearPickerOpen", "is-year-picker-open"],
|
||||
(value) => {
|
||||
emit("update:isYearPickerOpen", value);
|
||||
emit("yearPickerOpenChange", value);
|
||||
},
|
||||
);
|
||||
const yearOpen = computed(() => yearModel.value.value);
|
||||
function disabledDay(value: DateValue) {
|
||||
return (
|
||||
disabled.value ||
|
||||
toCalendarDate(value).compare(min.value) < 0 ||
|
||||
toCalendarDate(value).compare(max.value) > 0 ||
|
||||
!!props.isDateDisabled?.(value.copy()) ||
|
||||
!!selection.disabledDay?.(value.copy())
|
||||
);
|
||||
}
|
||||
const tabStop = computed(() => {
|
||||
const range = visible.value;
|
||||
if (
|
||||
!disabledDay(focus.value) &&
|
||||
focus.value.compare(range.start) >= 0 &&
|
||||
focus.value.compare(range.end) <= 0
|
||||
)
|
||||
return focus.value;
|
||||
let date = range.start;
|
||||
while (date.compare(range.end) <= 0) {
|
||||
if (!disabledDay(date)) return date;
|
||||
const next = date.add({ days: 1 });
|
||||
if (isSameDay(date, next)) break;
|
||||
date = next;
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
function focusDate(date: DateValue, moveDOM = false) {
|
||||
if (disabledDay(date)) return;
|
||||
const original = focusModel.value.value;
|
||||
const converted = toCalendar(date, original.calendar);
|
||||
if (!isSameDay(original, converted)) focusModel.request(converted.copy());
|
||||
const active = root.value?.ownerDocument.activeElement;
|
||||
const restoreControlledFocus =
|
||||
!!active &&
|
||||
root.value?.contains(active) &&
|
||||
active.getAttribute("data-slot") === `${prefix}-cell`;
|
||||
if (moveDOM || restoreControlledFocus)
|
||||
void nextTick(() => {
|
||||
if (yearOpen.value) return;
|
||||
const iso = (tabStop.value ?? focus.value).toString();
|
||||
root.value
|
||||
?.querySelector<HTMLElement>(
|
||||
`[data-slot="${prefix}-cell"][data-date="${iso}"]:not([data-outside-month])`,
|
||||
)
|
||||
?.focus();
|
||||
});
|
||||
}
|
||||
watch(
|
||||
() => dateValueKey(focus.value),
|
||||
() => {
|
||||
const active = root.value?.ownerDocument.activeElement;
|
||||
const retainFocus =
|
||||
!!active &&
|
||||
root.value?.contains(active) &&
|
||||
active.getAttribute("data-slot") === `${prefix}-cell`;
|
||||
if (
|
||||
focus.value.compare(visible.value.start) < 0 ||
|
||||
focus.value.compare(visible.value.end) > 0
|
||||
)
|
||||
anchor.value = aligned(focus.value);
|
||||
if (retainFocus)
|
||||
void nextTick(() => {
|
||||
if (!yearOpen.value)
|
||||
root.value
|
||||
?.querySelector<HTMLElement>(
|
||||
`[data-slot="${prefix}-cell"][tabindex="0"]`,
|
||||
)
|
||||
?.focus();
|
||||
});
|
||||
},
|
||||
{ flush: "sync" },
|
||||
);
|
||||
watch(
|
||||
[locale, () => props.visibleDuration, () => props.firstDayOfWeek],
|
||||
() => {
|
||||
anchor.value = aligned(focus.value);
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
watch(
|
||||
() => selection.dates.value.map(dateValueKey).join("|"),
|
||||
() => {
|
||||
if (
|
||||
selection.followSelected !== false &&
|
||||
!has("focusedValue") &&
|
||||
!has("focused-value") &&
|
||||
selection.dates.value[0]
|
||||
)
|
||||
focusDate(selection.dates.value[0]);
|
||||
},
|
||||
);
|
||||
function pageStep(direction: -1 | 1) {
|
||||
const { unit, count } = calendarDuration(props.visibleDuration);
|
||||
return {
|
||||
[unit]: direction * (props.pageBehavior === "single" ? 1 : count),
|
||||
};
|
||||
}
|
||||
function pageDisabled(direction: -1 | 1) {
|
||||
if (disabled.value || yearOpen.value) return true;
|
||||
const range = calendarRange(
|
||||
anchor.value.add(pageStep(direction)),
|
||||
options.value,
|
||||
);
|
||||
return (
|
||||
range.end.compare(min.value) < 0 || range.start.compare(max.value) > 0
|
||||
);
|
||||
}
|
||||
let pageRevision = 0;
|
||||
onBeforeUnmount(() => {
|
||||
pageRevision++;
|
||||
});
|
||||
function page(direction: -1 | 1) {
|
||||
if (pageDisabled(direction)) return;
|
||||
const nextAnchor = anchor.value.add(pageStep(direction));
|
||||
const range = calendarRange(nextAnchor, options.value);
|
||||
let date = focus.value.add(pageStep(direction));
|
||||
if (date.compare(min.value) < 0) date = min.value;
|
||||
if (date.compare(max.value) > 0) date = max.value;
|
||||
// Disabled target days must not make an otherwise navigable month inert.
|
||||
if (disabledDay(date)) {
|
||||
let candidate = range.start;
|
||||
while (candidate.compare(range.end) <= 0 && disabledDay(candidate)) {
|
||||
const next = candidate.add({ days: 1 });
|
||||
if (isSameDay(candidate, next)) return;
|
||||
candidate = next;
|
||||
}
|
||||
if (candidate.compare(range.end) > 0) return;
|
||||
date = candidate;
|
||||
}
|
||||
focusDate(date);
|
||||
const revision = ++pageRevision;
|
||||
void nextTick(() => {
|
||||
if (revision === pageRevision && isSameDay(focus.value, date))
|
||||
anchor.value = nextAnchor;
|
||||
});
|
||||
}
|
||||
function setYearOpen(value: boolean, restore = false) {
|
||||
if (disabled.value) return;
|
||||
yearModel.request(value);
|
||||
if (!value && restore)
|
||||
void nextTick(() => {
|
||||
if (!yearOpen.value) trigger.value?.focus();
|
||||
});
|
||||
}
|
||||
const context = {
|
||||
prefix,
|
||||
root,
|
||||
trigger,
|
||||
focus,
|
||||
anchor,
|
||||
options,
|
||||
min,
|
||||
max,
|
||||
disabled,
|
||||
tabStop,
|
||||
readOnly,
|
||||
multiple,
|
||||
invalid,
|
||||
dir,
|
||||
timeZone,
|
||||
yearOpen,
|
||||
headingId,
|
||||
selected: selection.selected,
|
||||
disabledDay,
|
||||
unavailable: selection.unavailable ?? (() => false),
|
||||
request: selection.request,
|
||||
range: selection.range,
|
||||
focusDate,
|
||||
page,
|
||||
pageDisabled,
|
||||
setYearOpen,
|
||||
} satisfies CalendarContext;
|
||||
provide(calendarKey, context);
|
||||
onMounted(() => {
|
||||
if (props.autoFocus && tabStop.value) focusDate(tabStop.value, true);
|
||||
});
|
||||
|
||||
return { ...context, visible };
|
||||
}
|
||||
@@ -191,7 +191,7 @@ export const CalendarYearPickerGrid = defineComponent({
|
||||
}).format(date.toDate("UTC"));
|
||||
function measure() {
|
||||
const grid = ctx.root.value?.querySelector<HTMLElement>(
|
||||
'[data-slot="calendar-grid"]',
|
||||
`[data-slot="${ctx.prefix}-grid"]`,
|
||||
);
|
||||
if (grid) {
|
||||
top.value = grid.offsetTop;
|
||||
@@ -206,7 +206,9 @@ export const CalendarYearPickerGrid = defineComponent({
|
||||
cell?.scrollIntoView?.({ block: "nearest" });
|
||||
}
|
||||
const rootGrid = computed(() =>
|
||||
ctx.root.value?.querySelector<HTMLElement>('[data-slot="calendar-grid"]'),
|
||||
ctx.root.value?.querySelector<HTMLElement>(
|
||||
`[data-slot="${ctx.prefix}-grid"]`,
|
||||
),
|
||||
);
|
||||
useResizeObserver(rootGrid, measure);
|
||||
onMounted(measure);
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import {
|
||||
GregorianCalendar,
|
||||
isSameDay,
|
||||
toCalendar,
|
||||
toCalendarDate,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
import { copyDateValue, dateValueKey } from "./value";
|
||||
|
||||
/** Complete accepted selection. Partial selection belongs to the private draft. */
|
||||
export interface CalendarDateRange<T extends DateValue = DateValue> {
|
||||
start: T;
|
||||
end: T;
|
||||
}
|
||||
export type CalendarRangeModel = CalendarDateRange | null;
|
||||
export const copyCalendarRange = (
|
||||
value: CalendarRangeModel | undefined,
|
||||
): CalendarRangeModel =>
|
||||
value
|
||||
? { start: copyDateValue(value.start), end: copyDateValue(value.end) }
|
||||
: null;
|
||||
export const calendarRangeKey = (value: CalendarRangeModel) =>
|
||||
value ? `${dateValueKey(value.start)}|${dateValueKey(value.end)}` : "empty";
|
||||
export function orderedCalendarRange(
|
||||
a: DateValue,
|
||||
b: DateValue,
|
||||
): CalendarDateRange {
|
||||
const start = toCalendarDate(a),
|
||||
end = toCalendarDate(b);
|
||||
return start.compare(end) <= 0
|
||||
? { start: start.copy(), end: end.copy() }
|
||||
: { start: end.copy(), end: start.copy() };
|
||||
}
|
||||
export function withinCalendarRange(
|
||||
date: DateValue,
|
||||
range: CalendarRangeModel,
|
||||
) {
|
||||
const day = toCalendarDate(date);
|
||||
return (
|
||||
!!range &&
|
||||
day.compare(toCalendarDate(range.start)) >= 0 &&
|
||||
day.compare(toCalendarDate(range.end)) <= 0
|
||||
);
|
||||
}
|
||||
/** Both endpoints preserve their own calendar, time precision and zone. */
|
||||
export function convertCalendarRange(
|
||||
range: CalendarDateRange,
|
||||
original: CalendarRangeModel,
|
||||
): CalendarDateRange {
|
||||
const convert = (day: DateValue, previous?: DateValue) => {
|
||||
const date = toCalendar(day, previous?.calendar ?? new GregorianCalendar());
|
||||
return previous
|
||||
? previous.set({
|
||||
era: date.era,
|
||||
year: date.year,
|
||||
month: date.month,
|
||||
day: date.day,
|
||||
})
|
||||
: toCalendarDate(date);
|
||||
};
|
||||
return {
|
||||
start: convert(range.start, original?.start),
|
||||
end: convert(range.end, original?.end),
|
||||
};
|
||||
}
|
||||
/** First interior barrier, not the endpoint itself: unavailable endpoints stay
|
||||
* focusable. Non-contiguous ranges may cross unavailable, never disabled days. */
|
||||
export function calendarRangeBarrier(
|
||||
anchor: DateValue,
|
||||
target: DateValue,
|
||||
disabled: (date: DateValue) => boolean,
|
||||
unavailable: (date: DateValue) => boolean,
|
||||
allowsNonContiguous = false,
|
||||
): DateValue | undefined {
|
||||
const start = toCalendarDate(anchor),
|
||||
end = toCalendarDate(target);
|
||||
const direction = end.compare(start) < 0 ? -1 : 1;
|
||||
let date = start.add({ days: direction });
|
||||
while (direction * date.compare(end) < 0) {
|
||||
if (disabled(date) || (!allowsNonContiguous && unavailable(date)))
|
||||
return date.copy();
|
||||
const next = date.add({ days: direction });
|
||||
if (isSameDay(next, date)) break;
|
||||
date = next;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -0,0 +1,453 @@
|
||||
import {
|
||||
computed,
|
||||
getCurrentInstance,
|
||||
onBeforeUnmount,
|
||||
shallowRef,
|
||||
watch,
|
||||
type ComputedRef,
|
||||
} from "vue";
|
||||
import {
|
||||
isSameDay,
|
||||
toCalendarDate,
|
||||
type CalendarDate,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
import { useChoiceValue } from "../choice/shared";
|
||||
import { useCalendarView, type CalendarViewProps } from "../calendar/view";
|
||||
import type { CalendarRangeInteraction } from "../calendar/context";
|
||||
import {
|
||||
calendarRangeBarrier,
|
||||
calendarRangeKey,
|
||||
convertCalendarRange,
|
||||
copyCalendarRange,
|
||||
orderedCalendarRange,
|
||||
withinCalendarRange,
|
||||
type CalendarRangeModel,
|
||||
} from "../date/range-selection";
|
||||
import { calendarDayState, dateValueKey } from "../date/value";
|
||||
import { calendarDuration, calendarRange } from "../date/calendar";
|
||||
|
||||
/** Private schema for the next public shell; not exported from the package root. */
|
||||
export interface RangeCalendarOptions extends Omit<
|
||||
CalendarViewProps,
|
||||
"isDateUnavailable"
|
||||
> {
|
||||
modelValue?: CalendarRangeModel;
|
||||
value?: CalendarRangeModel;
|
||||
defaultValue?: CalendarRangeModel;
|
||||
allowsNonContiguousRanges?: boolean;
|
||||
isDateUnavailable?: (
|
||||
date: DateValue,
|
||||
anchorDate: CalendarDate | null,
|
||||
) => boolean;
|
||||
}
|
||||
interface RangeEmit {
|
||||
(event: "update:modelValue", value: CalendarRangeModel): void;
|
||||
(event: "change", value: CalendarRangeModel): void;
|
||||
(event: "update:focusedValue", value: DateValue): void;
|
||||
(event: "focusChange", value: DateValue): void;
|
||||
(event: "update:isYearPickerOpen", value: boolean): void;
|
||||
(event: "yearPickerOpenChange", value: boolean): void;
|
||||
}
|
||||
interface Gesture {
|
||||
id: number;
|
||||
start: DateValue;
|
||||
previousAnchor: CalendarDate | null;
|
||||
previousEnd: CalendarDate | null;
|
||||
hadAnchor: boolean;
|
||||
moved: boolean;
|
||||
}
|
||||
/** Range selection owns only the accepted value and an uncommitted anchor.
|
||||
* All calendar geometry, focus, paging and year navigation have one shared owner. */
|
||||
export function useRangeCalendar(props: RangeCalendarOptions, emit: RangeEmit) {
|
||||
const instance = getCurrentInstance()!;
|
||||
const has = (key: string) => Object.hasOwn(instance.vnode.props ?? {}, key);
|
||||
const fallback = copyCalendarRange(props.defaultValue);
|
||||
const model = useChoiceValue<CalendarRangeModel>(
|
||||
() =>
|
||||
copyCalendarRange(
|
||||
has("modelValue") || has("model-value")
|
||||
? props.modelValue
|
||||
: props.value,
|
||||
),
|
||||
() => copyCalendarRange(fallback),
|
||||
["modelValue", "model-value", "value"],
|
||||
(value) => {
|
||||
emit("update:modelValue", copyCalendarRange(value));
|
||||
emit("change", copyCalendarRange(value));
|
||||
},
|
||||
);
|
||||
const anchorDate = shallowRef<CalendarDate | null>(null);
|
||||
const draftEnd = shallowRef<CalendarDate | null>(null);
|
||||
const dates = computed(() =>
|
||||
model.value.value ? [model.value.value.start, model.value.value.end] : [],
|
||||
);
|
||||
const unavailable = (date: DateValue) =>
|
||||
!!props.isDateUnavailable?.(date.copy(), anchorDate.value?.copy() ?? null);
|
||||
const baseDisabled = (date: DateValue) =>
|
||||
calendarDayState(date, {
|
||||
isDateDisabled: props.isDateDisabled,
|
||||
minValue: props.minValue ?? view.min.value,
|
||||
maxValue: props.maxValue ?? view.max.value,
|
||||
isDisabled: view.disabled.value,
|
||||
}).isDisabled;
|
||||
// Only an active draft constrains cross-barrier navigation. Cache by semantics,
|
||||
// not mutable DateValue identity; invalidated by reactive rules/bounds below.
|
||||
let barriers = new Map<string, ComputedRef<DateValue | undefined>>();
|
||||
function barrier(date: DateValue) {
|
||||
if (
|
||||
!anchorDate.value ||
|
||||
(!props.isDateUnavailable && !props.isDateDisabled)
|
||||
)
|
||||
return undefined;
|
||||
const key = dateValueKey(date);
|
||||
if (!barriers.has(key))
|
||||
barriers.set(
|
||||
key,
|
||||
computed(() =>
|
||||
anchorDate.value
|
||||
? calendarRangeBarrier(
|
||||
anchorDate.value,
|
||||
date,
|
||||
baseDisabled,
|
||||
unavailable,
|
||||
!!props.allowsNonContiguousRanges,
|
||||
)
|
||||
: undefined,
|
||||
),
|
||||
);
|
||||
return barriers.get(key)?.value;
|
||||
}
|
||||
function allowed(date: DateValue) {
|
||||
return (
|
||||
!view.disabled.value &&
|
||||
!view.readOnly.value &&
|
||||
!view.yearOpen.value &&
|
||||
!baseDisabled(date) &&
|
||||
!unavailable(date) &&
|
||||
!barrier(date)
|
||||
);
|
||||
}
|
||||
const highlightedRange = computed(() => {
|
||||
if (anchorDate.value)
|
||||
return orderedCalendarRange(
|
||||
anchorDate.value,
|
||||
draftEnd.value ?? anchorDate.value,
|
||||
);
|
||||
return model.value.value
|
||||
? orderedCalendarRange(model.value.value.start, model.value.value.end)
|
||||
: null;
|
||||
});
|
||||
const invalidSelection = computed(() => {
|
||||
const value = model.value.value;
|
||||
if (anchorDate.value) return false;
|
||||
return (
|
||||
!!value &&
|
||||
(toCalendarDate(value.start).compare(toCalendarDate(value.end)) > 0 ||
|
||||
baseDisabled(value.start) ||
|
||||
baseDisabled(value.end) ||
|
||||
unavailable(value.start) ||
|
||||
unavailable(value.end))
|
||||
);
|
||||
});
|
||||
function selected(date: DateValue) {
|
||||
return (
|
||||
withinCalendarRange(date, highlightedRange.value) &&
|
||||
!baseDisabled(date) &&
|
||||
!unavailable(date)
|
||||
);
|
||||
}
|
||||
function begin(date: DateValue) {
|
||||
draftEnd.value = toCalendarDate(date).copy();
|
||||
anchorDate.value = toCalendarDate(date).copy();
|
||||
barriers.clear();
|
||||
}
|
||||
function complete(date: DateValue) {
|
||||
if (!anchorDate.value || !allowed(date)) return false;
|
||||
if (baseDisabled(anchorDate.value) || unavailable(anchorDate.value)) {
|
||||
cancel();
|
||||
return false;
|
||||
}
|
||||
const range = orderedCalendarRange(anchorDate.value, date);
|
||||
const value = convertCalendarRange(range, model.value.value ?? fallback);
|
||||
anchorDate.value = null;
|
||||
draftEnd.value = null;
|
||||
barriers.clear();
|
||||
model.request(copyCalendarRange(value));
|
||||
return true;
|
||||
}
|
||||
function activate(
|
||||
date: DateValue,
|
||||
source: "keyboard" | "virtual",
|
||||
event?: Event,
|
||||
) {
|
||||
if (event?.defaultPrevented && source !== "keyboard") return;
|
||||
if (!allowed(date)) return;
|
||||
if (anchorDate.value) {
|
||||
complete(date);
|
||||
return;
|
||||
}
|
||||
begin(date);
|
||||
if (source === "keyboard") {
|
||||
// Advancing focus exposes the range preview to keyboard users. Only an
|
||||
// accepted focus is used, so a rejecting parent cannot create a ghost end.
|
||||
for (const direction of [1, -1]) {
|
||||
const next = date.add({ days: direction });
|
||||
if (!isSameDay(next, date) && allowed(next)) {
|
||||
view.focusDate(next, true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let gesture: Gesture | undefined;
|
||||
let pendingClick: Gesture | undefined;
|
||||
let detach = () => {};
|
||||
let ignoreClick = false;
|
||||
let clickTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
function resetClick() {
|
||||
clearTimeout(clickTimer);
|
||||
clickTimer = undefined;
|
||||
pendingClick = undefined;
|
||||
ignoreClick = false;
|
||||
}
|
||||
function restore(previous: Gesture) {
|
||||
anchorDate.value = previous.previousAnchor?.copy() ?? null;
|
||||
draftEnd.value = previous.previousEnd?.copy() ?? null;
|
||||
barriers.clear();
|
||||
}
|
||||
function stopGesture(rollback = false) {
|
||||
if (gesture && rollback) restore(gesture);
|
||||
gesture = undefined;
|
||||
detach();
|
||||
detach = () => {};
|
||||
}
|
||||
function cancel() {
|
||||
const active = !!anchorDate.value || !!gesture || !!pendingClick;
|
||||
stopGesture();
|
||||
resetClick();
|
||||
anchorDate.value = null;
|
||||
draftEnd.value = null;
|
||||
barriers.clear();
|
||||
return active;
|
||||
}
|
||||
function armClickExpiry() {
|
||||
clearTimeout(clickTimer);
|
||||
clickTimer = setTimeout(() => {
|
||||
// A stopped/cancelled native click never leaves a transient draft behind.
|
||||
if (pendingClick) restore(pendingClick);
|
||||
resetClick();
|
||||
}, 0);
|
||||
}
|
||||
const range: CalendarRangeInteraction = {
|
||||
focusTarget(date) {
|
||||
const blocked = barrier(date);
|
||||
if (!blocked || !anchorDate.value) return date;
|
||||
return blocked.add({ days: date.compare(anchorDate.value) < 0 ? 1 : -1 });
|
||||
},
|
||||
state(date) {
|
||||
const highlighted = highlightedRange.value;
|
||||
return {
|
||||
isSelectionStart:
|
||||
selected(date) && !!highlighted && isSameDay(date, highlighted.start),
|
||||
isSelectionEnd:
|
||||
selected(date) && !!highlighted && isSameDay(date, highlighted.end),
|
||||
isInvalid:
|
||||
!anchorDate.value &&
|
||||
view.invalid.value &&
|
||||
withinCalendarRange(date, highlighted),
|
||||
};
|
||||
},
|
||||
activate,
|
||||
cancel,
|
||||
pointerDown(date, event) {
|
||||
if (
|
||||
event.defaultPrevented ||
|
||||
event.button !== 0 ||
|
||||
event.isPrimary === false ||
|
||||
event.pointerType === "touch" ||
|
||||
!allowed(date)
|
||||
)
|
||||
return;
|
||||
stopGesture(true);
|
||||
resetClick();
|
||||
const previous: Gesture = {
|
||||
id: event.pointerId,
|
||||
start: date.copy(),
|
||||
previousAnchor: anchorDate.value?.copy() ?? null,
|
||||
previousEnd: draftEnd.value?.copy() ?? null,
|
||||
hadAnchor: !!anchorDate.value,
|
||||
moved: false,
|
||||
};
|
||||
gesture = previous;
|
||||
if (!previous.hadAnchor) {
|
||||
const current = model.value.value;
|
||||
const opposite =
|
||||
current &&
|
||||
!invalidSelection.value &&
|
||||
(isSameDay(date, current.start)
|
||||
? current.end
|
||||
: isSameDay(date, current.end)
|
||||
? current.start
|
||||
: undefined);
|
||||
begin(opposite || date);
|
||||
}
|
||||
view.focusDate(date, true);
|
||||
if (anchorDate.value && allowed(view.focus.value))
|
||||
draftEnd.value = view.focus.value.copy();
|
||||
const doc = view.root.value?.ownerDocument;
|
||||
if (!doc) return;
|
||||
// No global queue/capture: these listeners live only for this gesture.
|
||||
// Capture+task also cleans up when consumers stop bubbling pointerup.
|
||||
// Browsers can flush microtasks BETWEEN native event listeners; cleanup
|
||||
// must wait for the whole dispatch, not just the capture callback.
|
||||
let releaseTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
const release = (up: PointerEvent) => {
|
||||
if (up.pointerId !== previous.id) return;
|
||||
releaseTimer = setTimeout(() => {
|
||||
if (gesture === previous) stopGesture(true);
|
||||
}, 0);
|
||||
};
|
||||
const abort = (cancelled: PointerEvent) => {
|
||||
if (cancelled.pointerId === previous.id) stopGesture(true);
|
||||
};
|
||||
const blur = () => stopGesture(true);
|
||||
doc.addEventListener("pointerup", release, true);
|
||||
doc.addEventListener("pointercancel", abort, true);
|
||||
doc.defaultView?.addEventListener("blur", blur);
|
||||
detach = () => {
|
||||
clearTimeout(releaseTimer);
|
||||
doc.removeEventListener("pointerup", release, true);
|
||||
doc.removeEventListener("pointercancel", abort, true);
|
||||
doc.defaultView?.removeEventListener("blur", blur);
|
||||
};
|
||||
},
|
||||
pointerEnter(date, event) {
|
||||
if (
|
||||
event.defaultPrevented ||
|
||||
event.pointerType === "touch" ||
|
||||
!anchorDate.value ||
|
||||
!allowed(date)
|
||||
)
|
||||
return;
|
||||
if (gesture) {
|
||||
if (event.pointerId !== gesture.id) return;
|
||||
if (!isSameDay(date, gesture.start)) gesture.moved = true;
|
||||
}
|
||||
view.focusDate(date, true);
|
||||
},
|
||||
pointerUp(date, event) {
|
||||
if (!gesture || gesture.id !== event.pointerId) return;
|
||||
const previous = gesture;
|
||||
if (event.defaultPrevented || !allowed(date)) {
|
||||
stopGesture(true);
|
||||
return;
|
||||
}
|
||||
if (previous.moved) {
|
||||
complete(date);
|
||||
stopGesture();
|
||||
ignoreClick = true;
|
||||
} else {
|
||||
stopGesture();
|
||||
pendingClick = previous;
|
||||
}
|
||||
armClickExpiry();
|
||||
},
|
||||
click(date, event) {
|
||||
if (event.defaultPrevented) {
|
||||
if (pendingClick) restore(pendingClick);
|
||||
else if (gesture) stopGesture(true);
|
||||
resetClick();
|
||||
return;
|
||||
}
|
||||
if (ignoreClick && event.detail > 0) {
|
||||
resetClick();
|
||||
return;
|
||||
}
|
||||
const pending = pendingClick;
|
||||
resetClick();
|
||||
if (!allowed(date)) return;
|
||||
if (pending && !pending.hadAnchor) begin(date);
|
||||
else activate(date, "virtual", event);
|
||||
view.focusDate(date);
|
||||
},
|
||||
};
|
||||
const view = useCalendarView(
|
||||
props,
|
||||
{
|
||||
dates,
|
||||
followSelected: false,
|
||||
alignment(date, options) {
|
||||
const { unit, count } = calendarDuration(options.visibleDuration);
|
||||
const centered = calendarRange(
|
||||
date.subtract({ [unit]: Math.floor((count - 1) / 2) }),
|
||||
options,
|
||||
);
|
||||
return model.value.value &&
|
||||
toCalendarDate(model.value.value.end).compare(centered.end) > 0
|
||||
? "start"
|
||||
: "center";
|
||||
},
|
||||
selected,
|
||||
request: (date) => activate(date, "virtual"),
|
||||
unavailable,
|
||||
multiple: () => true,
|
||||
invalid: () => invalidSelection.value,
|
||||
disabledDay: (date) => !!barrier(date),
|
||||
range,
|
||||
},
|
||||
emit,
|
||||
"range-calendar",
|
||||
);
|
||||
watch(
|
||||
() => dateValueKey(view.focus.value),
|
||||
() => {
|
||||
if (!anchorDate.value) return;
|
||||
const date = view.focus.value;
|
||||
if (!baseDisabled(date) && !unavailable(date) && !barrier(date))
|
||||
draftEnd.value = date.copy();
|
||||
},
|
||||
{ flush: "sync" },
|
||||
);
|
||||
watch(
|
||||
() => calendarRangeKey(model.value.value),
|
||||
() => cancel(),
|
||||
{ flush: "sync" },
|
||||
);
|
||||
watch(
|
||||
[
|
||||
anchorDate,
|
||||
() => props.isDateUnavailable,
|
||||
() => props.isDateDisabled,
|
||||
() => props.allowsNonContiguousRanges,
|
||||
() => dateValueKey(props.minValue),
|
||||
() => dateValueKey(props.maxValue),
|
||||
() => view.options.value.locale,
|
||||
],
|
||||
() => {
|
||||
barriers = new Map();
|
||||
},
|
||||
{ flush: "sync" },
|
||||
);
|
||||
watch(
|
||||
[view.disabled, view.readOnly, view.yearOpen],
|
||||
([disabled, readonly, yearOpen]) => {
|
||||
if (disabled || readonly || yearOpen) cancel();
|
||||
},
|
||||
{ flush: "sync" },
|
||||
);
|
||||
watch(
|
||||
() =>
|
||||
!!anchorDate.value &&
|
||||
(baseDisabled(anchorDate.value) || unavailable(anchorDate.value)),
|
||||
(invalid) => {
|
||||
if (invalid) cancel();
|
||||
},
|
||||
{ flush: "sync" },
|
||||
);
|
||||
onBeforeUnmount(() => {
|
||||
stopGesture();
|
||||
resetClick();
|
||||
});
|
||||
return { ...view, model, anchorDate, highlightedRange, cancel };
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
<script setup lang="ts">
|
||||
// Integration fixture, not a public component or a documentation preview.
|
||||
import { useAttrs } from "vue";
|
||||
import type { DateValue } from "@internationalized/date";
|
||||
import {
|
||||
useRangeCalendar,
|
||||
type RangeCalendarOptions,
|
||||
} from "../../src/components/range-calendar/use-range-calendar";
|
||||
import {
|
||||
copyCalendarRange,
|
||||
type CalendarRangeModel,
|
||||
} from "../../src/components/date/range-selection";
|
||||
import { calendarHeading } from "../../src/components/date/calendar";
|
||||
import {
|
||||
CalendarHeader,
|
||||
CalendarHeading,
|
||||
CalendarNavButton,
|
||||
CalendarGrid,
|
||||
CalendarGridHeader,
|
||||
CalendarGridBody,
|
||||
} from "../../src/components/calendar/parts";
|
||||
import {
|
||||
CalendarYearPickerTrigger,
|
||||
CalendarYearPickerTriggerHeading,
|
||||
CalendarYearPickerTriggerIndicator,
|
||||
CalendarYearPickerGrid,
|
||||
CalendarYearPickerGridBody,
|
||||
} from "../../src/components/calendar/year-picker";
|
||||
defineOptions({ inheritAttrs: false });
|
||||
const props = defineProps<RangeCalendarOptions>();
|
||||
const emit = defineEmits<{
|
||||
"update:modelValue": [value: CalendarRangeModel];
|
||||
change: [value: CalendarRangeModel];
|
||||
"update:focusedValue": [value: DateValue];
|
||||
focusChange: [value: DateValue];
|
||||
"update:isYearPickerOpen": [value: boolean];
|
||||
yearPickerOpenChange: [value: boolean];
|
||||
}>();
|
||||
const attrs = useAttrs();
|
||||
const view = useRangeCalendar(props, emit);
|
||||
const {
|
||||
root,
|
||||
anchor,
|
||||
options,
|
||||
visible,
|
||||
dir,
|
||||
disabled,
|
||||
readOnly,
|
||||
invalid,
|
||||
yearOpen,
|
||||
model,
|
||||
anchorDate,
|
||||
highlightedRange,
|
||||
} = view;
|
||||
defineExpose({ view });
|
||||
</script>
|
||||
<template>
|
||||
<component
|
||||
:is="as ?? 'div'"
|
||||
ref="root"
|
||||
v-bind="attrs"
|
||||
class="hv-range-calendar"
|
||||
:class="{
|
||||
'hv-range-calendar--week-view': visible.unit === 'weeks',
|
||||
'hv-range-calendar--day-view': visible.unit === 'days',
|
||||
}"
|
||||
role="group"
|
||||
:dir="dir"
|
||||
data-slot="range-calendar"
|
||||
:aria-label="
|
||||
(attrs['aria-label'] as string | undefined) ??
|
||||
(attrs['aria-labelledby'] ? undefined : calendarHeading(anchor, options))
|
||||
"
|
||||
:aria-disabled="disabled || undefined"
|
||||
:data-disabled="disabled || undefined"
|
||||
:aria-invalid="invalid || undefined"
|
||||
>
|
||||
<slot
|
||||
:value="copyCalendarRange(model.value.value)"
|
||||
:anchor-date="anchorDate?.copy() ?? null"
|
||||
:highlighted-range="copyCalendarRange(highlightedRange)"
|
||||
:is-disabled="disabled"
|
||||
:is-read-only="readOnly"
|
||||
:is-invalid="invalid"
|
||||
:is-year-picker-open="yearOpen"
|
||||
>
|
||||
<CalendarHeader>
|
||||
<CalendarYearPickerTrigger>
|
||||
<CalendarYearPickerTriggerHeading />
|
||||
<CalendarYearPickerTriggerIndicator />
|
||||
</CalendarYearPickerTrigger>
|
||||
<CalendarNavButton slot="previous" />
|
||||
<CalendarNavButton slot="next" />
|
||||
</CalendarHeader>
|
||||
<CalendarGrid>
|
||||
<CalendarGridHeader />
|
||||
<CalendarGridBody />
|
||||
</CalendarGrid>
|
||||
<CalendarYearPickerGrid>
|
||||
<CalendarYearPickerGridBody />
|
||||
</CalendarYearPickerGrid>
|
||||
</slot>
|
||||
</component>
|
||||
</template>
|
||||
Generated
+3
@@ -90,6 +90,9 @@ importers:
|
||||
'@heroui-vue/styles':
|
||||
specifier: workspace:*
|
||||
version: link:../../packages/styles
|
||||
'@internationalized/date':
|
||||
specifier: 3.12.4
|
||||
version: 3.12.4
|
||||
vue:
|
||||
specifier: ^3.5.44
|
||||
version: 3.5.44(typescript@5.9.3)
|
||||
|
||||
@@ -27,3 +27,5 @@ DATE-02 增加 `consume-date-field.mjs` / `date-field-contract.ts`。独立消
|
||||
M35–M36 使用 `consume-m35-m36.mjs` / `m35-m36-contract.ts`,新建 `/private/tmp/heroui-m35-consumer`。pnpm 11 的本地样式 tarball override 写在消费者 `pnpm-workspace.yaml`;不依赖已弃用的 package.json pnpm 字段。分别验证 ESM/CSS、真正 node SSR、所有部件导出,以及 bundler/NodeNext 类型正反例(含 Promise 参数推断)。
|
||||
|
||||
DATE-03 新增 `consume-calendar.mjs` / `calendar-contract.ts`,安装两份新 tarball 后运行 Node ESM/SSR/CSS 与 NodeNext/bundler 类型正反例,保留 DateField/Select 回归。Calendar 的泛型 Root 使用实际 SFC 参数类型核对单选、事件推断与错误模型,Cell/YearPicker Props 和作用域插槽不能退化为 any。
|
||||
|
||||
DATE-04 提取共享 Calendar 视图并完成私有范围内核,公共 RangeCalendar 尚未导出。最终 tarball 在 `/private/tmp/heroui-range-core-consumer` 运行 Calendar/DateField/Select 的 ESM/SSR/CSS 与两种解析模式正反类型回归;私有范围的 node SSR / 实际水合在工作区测试,不能据此声明公共范围产物已验收。公开范围下一轮须新增自己的完整消费契约。
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// @vitest-environment node
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { createSSRApp, defineComponent, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import { CalendarDate, parseZonedDateTime } from "@internationalized/date";
|
||||
import Range from "../packages/vue/tests/fixtures/RangeCalendarFoundation.vue";
|
||||
describe("range foundation actual node SSR", () => {
|
||||
it("renders complete semantic ranges, namespace and closed year layer without browser globals", async () => {
|
||||
const start = new CalendarDate(2024, 2, 10),
|
||||
end = start.add({ days: 3 });
|
||||
const html = await renderToString(
|
||||
createSSRApp(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(Range, {
|
||||
defaultValue: { start, end },
|
||||
timeZone: "UTC",
|
||||
"aria-label": "Trip dates",
|
||||
}),
|
||||
}),
|
||||
),
|
||||
);
|
||||
expect(html).toContain('data-slot="range-calendar-grid"');
|
||||
expect(html).toContain('role="grid"');
|
||||
expect(html).toContain('data-selection-start="true"');
|
||||
expect(html).toContain('data-selection-end="true"');
|
||||
expect(html).toContain('aria-hidden="true" inert');
|
||||
expect(html).not.toContain('name="');
|
||||
});
|
||||
it("retains full zoned accepted endpoints while rendering a locale-specific leap month", async () => {
|
||||
const start = parseZonedDateTime(
|
||||
"2024-02-28T13:14:45.123-08:00[America/Los_Angeles]",
|
||||
),
|
||||
end = start.add({ days: 2 });
|
||||
const html = await renderToString(
|
||||
createSSRApp(
|
||||
defineComponent({
|
||||
render: () =>
|
||||
h(Range, {
|
||||
defaultValue: { start, end },
|
||||
locale: "fa-IR-u-ca-persian",
|
||||
timeZone: "America/Los_Angeles",
|
||||
visibleDuration: { weeks: 2 },
|
||||
}),
|
||||
}),
|
||||
),
|
||||
);
|
||||
expect(html).toContain("hv-range-calendar--week-view");
|
||||
expect(html).toContain('data-selected="true"');
|
||||
expect(html).not.toContain("Invalid Date");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,563 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { mount, flushPromises } from "@vue/test-utils";
|
||||
import { createSSRApp, defineComponent, shallowRef, type Component } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import {
|
||||
CalendarDate,
|
||||
CalendarDateTime,
|
||||
PersianCalendar,
|
||||
toCalendar,
|
||||
parseZonedDateTime,
|
||||
type DateValue,
|
||||
} from "@internationalized/date";
|
||||
import Range from "../packages/vue/tests/fixtures/RangeCalendarFoundation.vue";
|
||||
import * as library from "../packages/vue/src/index";
|
||||
import {
|
||||
calendarRangeBarrier,
|
||||
convertCalendarRange,
|
||||
orderedCalendarRange,
|
||||
type CalendarRangeModel,
|
||||
} from "../packages/vue/src/components/date/range-selection";
|
||||
const initial = new CalendarDate(2024, 2, 10);
|
||||
const wrappers: ReturnType<typeof mount>[] = [];
|
||||
afterEach(() => {
|
||||
wrappers.splice(0).forEach((w) => w.unmount());
|
||||
document.body.innerHTML = "";
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
function fixture(attrs = "", setup = () => ({}), children = "") {
|
||||
const w = mount(
|
||||
defineComponent({
|
||||
components: {
|
||||
Range,
|
||||
...(Object.fromEntries(
|
||||
Object.entries(library).filter(([name]) =>
|
||||
name.startsWith("Calendar"),
|
||||
),
|
||||
) as Record<string, Component>),
|
||||
},
|
||||
setup: () => ({ initial, ...setup() }),
|
||||
template: `<Range aria-label="Trip dates" :default-focused-value="initial" ${attrs}>${children}</Range>`,
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
wrappers.push(w);
|
||||
return w;
|
||||
}
|
||||
const cell = (w: ReturnType<typeof mount>, day: number, month = 2) =>
|
||||
w.get<HTMLElement>(
|
||||
`[data-slot="range-calendar-cell"][data-date="2024-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}"]:not([data-outside-month])`,
|
||||
);
|
||||
const changes = (w: ReturnType<typeof mount>) =>
|
||||
(w.getComponent(Range).emitted("change") ?? []).map(
|
||||
([value]) => value as CalendarRangeModel,
|
||||
);
|
||||
const values = (w: ReturnType<typeof mount>) =>
|
||||
changes(w).map((v) => v && [v.start.toString(), v.end.toString()]);
|
||||
async function click(w: ReturnType<typeof mount>, day: number) {
|
||||
await cell(w, day).trigger("click");
|
||||
await flushPromises();
|
||||
}
|
||||
async function key(
|
||||
w: ReturnType<typeof mount>,
|
||||
day: number,
|
||||
key: string,
|
||||
other = {},
|
||||
) {
|
||||
cell(w, day).element.focus();
|
||||
await cell(w, day).trigger("keydown", { key, code: key, ...other });
|
||||
await flushPromises();
|
||||
}
|
||||
async function pointer(
|
||||
w: ReturnType<typeof mount>,
|
||||
day: number,
|
||||
type: string,
|
||||
other: { click?: boolean; [key: string]: unknown } = {},
|
||||
) {
|
||||
const event = new Event(type, { bubbles: true, cancelable: true });
|
||||
Object.assign(event, {
|
||||
pointerId: 1,
|
||||
pointerType: "mouse",
|
||||
button: 0,
|
||||
isPrimary: true,
|
||||
...other,
|
||||
});
|
||||
cell(w, day).element.dispatchEvent(event);
|
||||
if (other.click)
|
||||
cell(w, day).element.dispatchEvent(
|
||||
new MouseEvent("click", { bubbles: true, cancelable: true, detail: 1 }),
|
||||
);
|
||||
await flushPromises();
|
||||
return event;
|
||||
}
|
||||
const gridChildren =
|
||||
'<CalendarGrid><CalendarGridHeader/><CalendarGridBody v-slot="{date}"><CalendarCell :date="date"/></CalendarGridBody></CalendarGrid>';
|
||||
describe("private range selection and shared calendar integration", () => {
|
||||
it("keeps partial drafts out of the accepted value and orders reverse/same-day selection", async () => {
|
||||
const w = fixture();
|
||||
await click(w, 15);
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
expect(cell(w, 15).attributes("data-selection-start")).toBe("true");
|
||||
await click(w, 10);
|
||||
expect(values(w)).toEqual([["2024-02-10", "2024-02-15"]]);
|
||||
expect(cell(w, 12).attributes("data-selected")).toBe("true");
|
||||
expect(cell(w, 10).attributes("data-selection-start")).toBe("true");
|
||||
expect(cell(w, 15).attributes("data-selection-end")).toBe("true");
|
||||
await click(w, 20);
|
||||
await click(w, 20);
|
||||
expect(values(w)[1]).toEqual(["2024-02-20", "2024-02-20"]);
|
||||
expect(w.find("input[name]").exists()).toBe(false);
|
||||
expect(w.get("table").attributes("aria-multiselectable")).toBe("true");
|
||||
});
|
||||
it("reverts controlled rejection and retries the same complete proposal", async () => {
|
||||
const value = { start: initial, end: initial.add({ days: 2 }) };
|
||||
const w = fixture(':model-value="value"', () => ({ value }));
|
||||
for (let n = 0; n < 2; n++) {
|
||||
await click(w, 15);
|
||||
await click(w, 17);
|
||||
}
|
||||
expect(values(w)).toEqual([
|
||||
["2024-02-15", "2024-02-17"],
|
||||
["2024-02-15", "2024-02-17"],
|
||||
]);
|
||||
expect(cell(w, 10).attributes("data-selected")).toBe("true");
|
||||
expect(cell(w, 15).attributes("data-selected")).toBeUndefined();
|
||||
expect(value.start.day).toBe(10);
|
||||
});
|
||||
it("gives explicit modelValue null priority over value/defaultValue", async () => {
|
||||
const value = { start: initial, end: initial.add({ days: 2 }) };
|
||||
const w = fixture(
|
||||
':model-value="null" :value="value" :default-value="value"',
|
||||
() => ({ value }),
|
||||
);
|
||||
expect(
|
||||
w.find('[data-slot="range-calendar-cell"][data-selected]').exists(),
|
||||
).toBe(false);
|
||||
await click(w, 15);
|
||||
await click(w, 17);
|
||||
expect(
|
||||
w.find('[data-slot="range-calendar-cell"][data-selected]').exists(),
|
||||
).toBe(false);
|
||||
expect(changes(w)).toHaveLength(1);
|
||||
});
|
||||
it("captures defaults once, copies endpoints and keeps separate endpoint precision/zone", async () => {
|
||||
const start = new CalendarDateTime(2024, 2, 10, 8, 9, 45, 123);
|
||||
const end = parseZonedDateTime(
|
||||
"2024-02-12T20:30:15.456-08:00[America/Los_Angeles]",
|
||||
);
|
||||
const value = shallowRef<NonNullable<CalendarRangeModel>>({ start, end });
|
||||
const w = fixture(':default-value="value"', () => ({ value }));
|
||||
value.value = { start: initial, end: initial };
|
||||
await flushPromises();
|
||||
await click(w, 15);
|
||||
await click(w, 17);
|
||||
const v = changes(w)[0]!;
|
||||
expect(v.start.toString()).toBe(start.set({ day: 15 }).toString());
|
||||
expect(v.end.toString()).toBe(end.set({ day: 17 }).toString());
|
||||
expect(start.day).toBe(10);
|
||||
expect(end.day).toBe(12);
|
||||
});
|
||||
it("cancels a draft on external selection replacement without synthesizing change", async () => {
|
||||
const value = shallowRef<CalendarRangeModel>(null);
|
||||
const w = fixture('v-model="value"', () => ({ value }));
|
||||
await click(w, 15);
|
||||
value.value = { start: initial, end: initial.add({ days: 2 }) };
|
||||
await flushPromises();
|
||||
expect(cell(w, 15).attributes("data-selected")).toBeUndefined();
|
||||
expect(cell(w, 10).attributes("data-selection-start")).toBe("true");
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
await click(w, 20);
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
});
|
||||
it("advances keyboard focus, previews accepted focus, commits once and cancels drafts with Escape", async () => {
|
||||
const w = fixture();
|
||||
await key(w, 10, "Enter");
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
expect(document.activeElement).toBe(cell(w, 11).element);
|
||||
await key(w, 11, "ArrowRight");
|
||||
expect(cell(w, 12).attributes("data-selection-end")).toBe("true");
|
||||
await key(w, 12, "Enter");
|
||||
expect(values(w)).toEqual([["2024-02-10", "2024-02-12"]]);
|
||||
expect(document.activeElement).toBe(cell(w, 12).element);
|
||||
await key(w, 15, " ");
|
||||
await key(w, 16, "Escape");
|
||||
expect(cell(w, 10).attributes("data-selection-start")).toBe("true");
|
||||
await key(w, 16, "Enter", { repeat: true });
|
||||
expect(changes(w)).toHaveLength(1);
|
||||
});
|
||||
it("does not turn rejected controlled focus into a ghost preview", async () => {
|
||||
const w = fixture(':focused-value="initial"');
|
||||
await key(w, 10, "Enter");
|
||||
expect(document.activeElement).toBe(cell(w, 10).element);
|
||||
expect(cell(w, 11).attributes("data-selected")).toBeUndefined();
|
||||
await key(w, 10, "ArrowRight");
|
||||
expect(cell(w, 11).attributes("data-selected")).toBeUndefined();
|
||||
await key(w, 10, "Enter");
|
||||
expect(values(w)).toEqual([["2024-02-10", "2024-02-10"]]);
|
||||
});
|
||||
it("keeps unavailable dates focusable, blocks crossing barriers and terminates keyboard navigation", async () => {
|
||||
const w = fixture(':is-date-unavailable="d=>d.day===12"');
|
||||
await click(w, 10);
|
||||
expect(cell(w, 12).attributes("disabled")).toBeUndefined();
|
||||
expect(cell(w, 13).attributes("disabled")).toBeDefined();
|
||||
await key(w, 11, "ArrowRight");
|
||||
expect(document.activeElement).toBe(cell(w, 12).element);
|
||||
await key(w, 12, "ArrowRight");
|
||||
expect(document.activeElement).toBe(cell(w, 11).element);
|
||||
await click(w, 13);
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
await click(w, 11);
|
||||
expect(values(w)).toEqual([["2024-02-10", "2024-02-11"]]);
|
||||
});
|
||||
it("allows unavailable interiors but never endpoints, and never crosses disabled interiors", async () => {
|
||||
const w = fixture(
|
||||
'allows-non-contiguous-ranges :is-date-unavailable="d=>d.day===12"',
|
||||
);
|
||||
await click(w, 10);
|
||||
await click(w, 12);
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
await click(w, 15);
|
||||
expect(values(w)).toEqual([["2024-02-10", "2024-02-15"]]);
|
||||
expect(cell(w, 12).attributes("data-selected")).toBeUndefined();
|
||||
const blocked = fixture(
|
||||
'allows-non-contiguous-ranges :is-date-disabled="d=>d.day===12"',
|
||||
);
|
||||
await click(blocked, 10);
|
||||
await click(blocked, 15);
|
||||
expect(changes(blocked)).toHaveLength(0);
|
||||
});
|
||||
it("passes a copied anchor and reacts to captured reactive availability rules", async () => {
|
||||
const max = shallowRef(7);
|
||||
const seen: (string | null)[] = [];
|
||||
const unavailable = (date: DateValue, anchor: CalendarDate | null) => {
|
||||
seen.push(anchor?.toString() ?? null);
|
||||
return !!anchor && Math.abs(date.compare(anchor)) > max.value;
|
||||
};
|
||||
const w = fixture(':is-date-unavailable="unavailable"', () => ({
|
||||
unavailable,
|
||||
}));
|
||||
await click(w, 10);
|
||||
expect(cell(w, 15).attributes("aria-disabled")).toBeUndefined();
|
||||
max.value = 2;
|
||||
await flushPromises();
|
||||
expect(cell(w, 15).attributes("aria-disabled")).toBe("true");
|
||||
expect(seen).toContain("2024-02-10");
|
||||
await click(w, 12);
|
||||
expect(values(w)).toEqual([["2024-02-10", "2024-02-12"]]);
|
||||
});
|
||||
it("honors readonly, inherited Fieldset disabled, min/max and invalid accepted ranges", async () => {
|
||||
const ro = fixture("is-read-only");
|
||||
await key(ro, 10, "ArrowRight");
|
||||
expect(document.activeElement).toBe(cell(ro, 11).element);
|
||||
await click(ro, 11);
|
||||
expect(changes(ro)).toHaveLength(0);
|
||||
const w = fixture(
|
||||
':min-value="initial" :max-value="initial.add({days:5})" :model-value="{start:initial,end:initial.add({days:10})}"',
|
||||
);
|
||||
expect(cell(w, 9).attributes("disabled")).toBeDefined();
|
||||
expect(cell(w, 16).attributes("disabled")).toBeDefined();
|
||||
expect(
|
||||
w.get('[data-slot="range-calendar"]').attributes("aria-invalid"),
|
||||
).toBe("true");
|
||||
const inherited = mount(
|
||||
defineComponent({
|
||||
components: { Fieldset: library.Fieldset, Range },
|
||||
setup: () => ({ initial }),
|
||||
template:
|
||||
'<Fieldset disabled><Range :default-focused-value="initial"/></Fieldset>',
|
||||
}),
|
||||
{ attachTo: document.body },
|
||||
);
|
||||
wrappers.push(inherited);
|
||||
expect(cell(inherited, 10).attributes("disabled")).toBeDefined();
|
||||
});
|
||||
it("honors actual consumer click, keyboard and pointer cancellation", async () => {
|
||||
const w = fixture(
|
||||
"",
|
||||
() => ({}),
|
||||
gridChildren.replace(
|
||||
'<CalendarCell :date="date"/>',
|
||||
'<CalendarCell :date="date" @click.prevent @keydown.prevent @pointerdown.prevent/>',
|
||||
),
|
||||
);
|
||||
await click(w, 10);
|
||||
await key(w, 10, "Enter");
|
||||
await pointer(w, 10, "pointerdown");
|
||||
await pointer(w, 15, "pointerenter");
|
||||
await pointer(w, 15, "pointerup");
|
||||
expect(
|
||||
w.find('[data-slot="range-calendar-cell"][data-selected]').exists(),
|
||||
).toBe(false);
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
});
|
||||
it("commits mouse drag once and suppresses its compatibility click", async () => {
|
||||
const w = fixture();
|
||||
await pointer(w, 10, "pointerdown");
|
||||
await pointer(w, 15, "pointerenter");
|
||||
expect(cell(w, 13).attributes("data-selected")).toBe("true");
|
||||
await pointer(w, 15, "pointerup", { click: true });
|
||||
expect(values(w)).toEqual([["2024-02-10", "2024-02-15"]]);
|
||||
expect(cell(w, 10).attributes("data-selection-start")).toBe("true");
|
||||
});
|
||||
it("supports native two-click gestures without emitting a one-day range on first release", async () => {
|
||||
const w = fixture();
|
||||
for (const d of [10, 15]) {
|
||||
await pointer(w, d, "pointerdown");
|
||||
await pointer(w, d, "pointerup", { click: true });
|
||||
}
|
||||
expect(values(w)).toEqual([["2024-02-10", "2024-02-15"]]);
|
||||
});
|
||||
it("adjusts a selected boundary by dragging, but a stationary boundary click starts a new range", async () => {
|
||||
const w = fixture(
|
||||
':default-value="{start:initial,end:initial.add({days:5})}"',
|
||||
);
|
||||
await pointer(w, 10, "pointerdown");
|
||||
await pointer(w, 8, "pointerenter");
|
||||
await pointer(w, 8, "pointerup");
|
||||
expect(values(w)).toEqual([["2024-02-08", "2024-02-15"]]);
|
||||
await pointer(w, 8, "pointerdown");
|
||||
await pointer(w, 8, "pointerup", { click: true });
|
||||
await click(w, 9);
|
||||
expect(values(w)[1]).toEqual(["2024-02-08", "2024-02-09"]);
|
||||
});
|
||||
it("rolls back cancelled gestures, outside releases and right/non-primary pointers", async () => {
|
||||
const w = fixture(
|
||||
':default-value="{start:initial,end:initial.add({days:2})}"',
|
||||
);
|
||||
await pointer(w, 15, "pointerdown");
|
||||
await pointer(w, 17, "pointerenter");
|
||||
const cancel = new Event("pointercancel", { bubbles: true });
|
||||
Object.assign(cancel, { pointerId: 1 });
|
||||
document.dispatchEvent(cancel);
|
||||
await flushPromises();
|
||||
expect(cell(w, 10).attributes("data-selection-start")).toBe("true");
|
||||
await pointer(w, 15, "pointerdown");
|
||||
const up = new Event("pointerup", { bubbles: true });
|
||||
Object.assign(up, { pointerId: 1 });
|
||||
document.body.dispatchEvent(up);
|
||||
await new Promise((resolve) => setTimeout(resolve, 1));
|
||||
await flushPromises();
|
||||
expect(cell(w, 15).attributes("data-selected")).toBeUndefined();
|
||||
await pointer(w, 15, "pointerdown", { button: 2 });
|
||||
await pointer(w, 17, "pointerenter");
|
||||
await pointer(w, 17, "pointerup");
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
});
|
||||
it("cleans gesture listeners and draft state when disabled/opening year picker/unmounting", async () => {
|
||||
const disabled = shallowRef(false);
|
||||
const w = fixture(':is-disabled="disabled"', () => ({ disabled }));
|
||||
await click(w, 10);
|
||||
disabled.value = true;
|
||||
await flushPromises();
|
||||
disabled.value = false;
|
||||
await flushPromises();
|
||||
await click(w, 15);
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
await w.get('[data-slot="calendar-year-picker-trigger"]').trigger("click");
|
||||
await flushPromises();
|
||||
expect(
|
||||
w
|
||||
.get('[data-slot="calendar-year-picker-grid"]')
|
||||
.attributes("aria-hidden"),
|
||||
).toBe("false");
|
||||
const fresh = fixture();
|
||||
const remove = vi.spyOn(document, "removeEventListener");
|
||||
await pointer(fresh, 10, "pointerdown");
|
||||
fresh.unmount();
|
||||
expect(remove.mock.calls.some(([name]) => name === "pointerup")).toBe(true);
|
||||
expect(remove.mock.calls.some(([name]) => name === "pointercancel")).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
it("keeps touch scroll free of pointer-down drafts and permits click-based touch selection", async () => {
|
||||
const w = fixture();
|
||||
await pointer(w, 10, "pointerdown", { pointerType: "touch" });
|
||||
expect(
|
||||
w.find('[data-slot="range-calendar-cell"][data-selected]').exists(),
|
||||
).toBe(false);
|
||||
await click(w, 10);
|
||||
await click(w, 15);
|
||||
expect(changes(w)).toHaveLength(1);
|
||||
});
|
||||
it("reuses week/day/RTL and year geometry contracts without another view owner", async () => {
|
||||
const w = fixture(':visible-duration="{weeks:2}" dir="rtl"');
|
||||
expect(w.findAll("tbody tr")).toHaveLength(2);
|
||||
await key(w, 10, "ArrowLeft");
|
||||
expect(document.activeElement).toBe(cell(w, 11).element);
|
||||
const d = fixture(':visible-duration="{days:10}"');
|
||||
expect(
|
||||
d.findAll('[data-slot="range-calendar-cell"]:not([disabled])'),
|
||||
).toHaveLength(10);
|
||||
});
|
||||
it("preserves public calendar endpoints while locale affects only the view", () => {
|
||||
const start = toCalendar(initial, new PersianCalendar()),
|
||||
end = toCalendar(initial.add({ days: 2 }), new PersianCalendar());
|
||||
const range = convertCalendarRange(
|
||||
orderedCalendarRange(initial.add({ days: 3 }), initial.add({ days: 5 })),
|
||||
{ start, end },
|
||||
);
|
||||
expect(range.start.calendar.identifier).toBe("persian");
|
||||
expect(range.end.calendar.identifier).toBe("persian");
|
||||
const empty = convertCalendarRange(orderedCalendarRange(start, end), null);
|
||||
expect(empty.start.calendar.identifier).toBe("gregory");
|
||||
expect(
|
||||
calendarRangeBarrier(
|
||||
initial,
|
||||
initial.add({ days: 5 }),
|
||||
() => false,
|
||||
(d) => d.day === 12,
|
||||
)?.day,
|
||||
).toBe(12);
|
||||
});
|
||||
it("reverts the pointer draft when the actual compatibility click is cancelled", async () => {
|
||||
const w = fixture(
|
||||
"",
|
||||
() => ({}),
|
||||
gridChildren.replace(
|
||||
'<CalendarCell :date="date"/>',
|
||||
'<CalendarCell :date="date" @click.prevent/>',
|
||||
),
|
||||
);
|
||||
await pointer(w, 10, "pointerdown");
|
||||
await pointer(w, 10, "pointerup", { click: true });
|
||||
expect(
|
||||
w.find('[data-slot="range-calendar-cell"][data-selected]').exists(),
|
||||
).toBe(false);
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
});
|
||||
it("cancels an anchor invalidated by new bounds or a captured rule", async () => {
|
||||
const min = shallowRef(initial),
|
||||
blocked = shallowRef(false);
|
||||
const w = fixture(
|
||||
':min-value="min" :is-date-unavailable="d=>blocked && d.day===10"',
|
||||
() => ({ min, blocked }),
|
||||
);
|
||||
await click(w, 10);
|
||||
min.value = initial.add({ days: 1 });
|
||||
await flushPromises();
|
||||
await click(w, 15);
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
await key(w, 15, "Escape");
|
||||
min.value = initial;
|
||||
await flushPromises();
|
||||
await click(w, 10);
|
||||
blocked.value = true;
|
||||
await flushPromises();
|
||||
await click(w, 15);
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
});
|
||||
it("keeps separate grids in a multi-month range and skips duplicate filler dates", async () => {
|
||||
const w = fixture(
|
||||
':visible-duration="{months:2}" selection-alignment="start"',
|
||||
() => ({}),
|
||||
'<CalendarGrid><CalendarGridHeader/><CalendarGridBody/></CalendarGrid><CalendarGrid :offset="{months:1}"><CalendarGridHeader/><CalendarGridBody/></CalendarGrid>',
|
||||
);
|
||||
await click(w, 28);
|
||||
await cell(w, 2, 3).trigger("click");
|
||||
await flushPromises();
|
||||
expect(values(w)).toEqual([["2024-02-28", "2024-03-02"]]);
|
||||
expect(w.findAll('[data-date="2024-03-01"]:not([disabled])')).toHaveLength(
|
||||
1,
|
||||
);
|
||||
expect(
|
||||
w.findAll('[data-slot="range-calendar-cell"][tabindex="0"]'),
|
||||
).toHaveLength(1);
|
||||
});
|
||||
it("keeps a rejected drag at the parent's value and permits an identical repeated drag", async () => {
|
||||
const w = fixture(
|
||||
':model-value="{start:initial,end:initial.add({days:5})}"',
|
||||
);
|
||||
for (let n = 0; n < 2; n++) {
|
||||
await pointer(w, 10, "pointerdown");
|
||||
await pointer(w, 8, "pointerenter");
|
||||
await pointer(w, 8, "pointerup", { click: true });
|
||||
}
|
||||
expect(values(w)).toEqual([
|
||||
["2024-02-08", "2024-02-15"],
|
||||
["2024-02-08", "2024-02-15"],
|
||||
]);
|
||||
expect(cell(w, 10).attributes("data-selection-start")).toBe("true");
|
||||
expect(cell(w, 8).attributes("data-selected")).toBeUndefined();
|
||||
});
|
||||
it("ignores foreign pointer releases and rolls back a consumer-cancelled pointerup", async () => {
|
||||
const w = fixture(
|
||||
"",
|
||||
() => ({}),
|
||||
gridChildren.replace(
|
||||
'<CalendarCell :date="date"/>',
|
||||
'<CalendarCell :date="date" @pointerup.prevent/>',
|
||||
),
|
||||
);
|
||||
await pointer(w, 10, "pointerdown");
|
||||
await pointer(w, 15, "pointerenter");
|
||||
await pointer(w, 15, "pointerup", { pointerId: 2 });
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
await pointer(w, 15, "pointerup");
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
expect(
|
||||
w.find('[data-slot="range-calendar-cell"][data-selected]').exists(),
|
||||
).toBe(false);
|
||||
});
|
||||
it("does not navigate or commit when a mouse drag crosses a disabled outside-month filler", async () => {
|
||||
const w = fixture();
|
||||
await pointer(w, 28, "pointerdown");
|
||||
const outside = w.get(
|
||||
'[data-slot="range-calendar-cell"][data-date="2024-03-01"][data-outside-month]',
|
||||
);
|
||||
for (const type of ["pointerenter", "pointerup"]) {
|
||||
const event = new Event(type, { bubbles: true, cancelable: true });
|
||||
Object.assign(event, { pointerId: 1, pointerType: "mouse", button: 0 });
|
||||
outside.element.dispatchEvent(event);
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 1));
|
||||
await flushPromises();
|
||||
expect(
|
||||
w.get('[data-slot="calendar-year-picker-trigger"]').text(),
|
||||
).toContain("February");
|
||||
expect(changes(w)).toHaveLength(0);
|
||||
expect(cell(w, 28).attributes("data-selected")).toBeUndefined();
|
||||
});
|
||||
it("aligns long accepted ranges at the start and keeps an explicit alignment override", () => {
|
||||
const children =
|
||||
"<CalendarHeader><CalendarHeading/></CalendarHeader><CalendarGrid><CalendarGridHeader/><CalendarGridBody/></CalendarGrid>";
|
||||
const props =
|
||||
':default-value="{start:initial,end:initial.add({months:4})}" :visible-duration="{months:3}"';
|
||||
const w = fixture(props, () => ({}), children);
|
||||
expect(
|
||||
w.get('[data-slot="range-calendar-heading"]').text().replace(/\s+/g, " "),
|
||||
).toBe("February – April 2024");
|
||||
const explicit = fixture(
|
||||
props + ' selection-alignment="center"',
|
||||
() => ({}),
|
||||
children,
|
||||
);
|
||||
expect(
|
||||
explicit
|
||||
.get('[data-slot="range-calendar-heading"]')
|
||||
.text()
|
||||
.replace(/\s+/g, " "),
|
||||
).toBe("January – March 2024");
|
||||
});
|
||||
it("hydrates an actual shared range table without replacing SSR nodes or leaking duplicate IDs", async () => {
|
||||
const App = defineComponent({
|
||||
components: { Range },
|
||||
setup: () => ({ initial }),
|
||||
template:
|
||||
'<div><Range :default-focused-value="initial" :default-value="{start:initial,end:initial.add({days:2})}"/><Range :default-focused-value="initial"/></div>',
|
||||
});
|
||||
const html = await renderToString(createSSRApp(App));
|
||||
const container = document.createElement("div");
|
||||
container.innerHTML = html;
|
||||
document.body.append(container);
|
||||
const table = container.querySelector("table");
|
||||
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
|
||||
const app = createSSRApp(App);
|
||||
app.mount(container);
|
||||
await flushPromises();
|
||||
expect(container.querySelector("table")).toBe(table);
|
||||
expect(warn).not.toHaveBeenCalled();
|
||||
const ids = Array.from(container.querySelectorAll("[id]"), (n) => n.id);
|
||||
expect(new Set(ids).size).toBe(ids.length);
|
||||
app.unmount();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user