feat: migrate Calendar and calendar year picker

This commit is contained in:
maoyingjie
2026-10-24 20:59:19 +08:00
parent 1c4ecc3def
commit 835d2e4d90
47 changed files with 4283 additions and 87 deletions
+2
View File
@@ -25,3 +25,5 @@ SELECT-01 增加 `consume-select.mjs` / `select-contract.ts`。新 tarball 安
DATE-02 增加 `consume-date-field.mjs` / `date-field-contract.ts`。独立消费者显式安装 `@internationalized/date@3.12.4`,运行完整 ISO 时区提交/SSR/样式检查,分别用 NodeNext 与 bundler 验证 DateValue、粒度、变体、范围和 segment 的正反类型,不从源码 alias 取公共类型。
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。
+84
View File
@@ -0,0 +1,84 @@
import { h } from "vue";
import { CalendarDate, type DateValue } from "@internationalized/date";
import {
Calendar,
CalendarCell,
CalendarGrid,
CalendarYearPickerCell,
type CalendarProps,
type CalendarCellProps,
type CalendarGridProps,
type CalendarYearPickerGridProps,
type CalendarYearPickerCellProps,
} from "@heroui-vue/components";
const date = new CalendarDate(2024, 2, 10);
const single: CalendarProps = {
modelValue: date,
visibleDuration: { months: 2 },
firstDayOfWeek: "mon",
};
const multiple: CalendarProps<"multiple"> = {
selectionMode: "multiple",
modelValue: [date],
};
const grid: CalendarGridProps = { offset: { months: 1 }, weekdayStyle: "long" };
const cell: CalendarCellProps = { date };
const year: CalendarYearPickerGridProps = {
visibleYears: 20,
format: { era: "short", year: "numeric" },
};
// @ts-expect-error single mode is not an array model
const wrong: CalendarProps = { modelValue: [date] };
const wrongMultiple: CalendarProps<"multiple"> = {
selectionMode: "multiple",
// @ts-expect-error multiple mode is not a scalar model
modelValue: date,
};
// @ts-expect-error visible duration has a single unit
const mixed: CalendarProps = { visibleDuration: { months: 1, weeks: 1 } };
// @ts-expect-error DateValue is not JS Date
const wrongDate: CalendarCellProps = { date: new Date() };
// @ts-expect-error weekday format is explicit
const wrongGrid: CalendarGridProps = { weekdayStyle: "numeric" };
// @ts-expect-error no text selection mode
const wrongMode: CalendarProps = { selectionMode: "none" };
type RootProps = Parameters<typeof Calendar<"single">>[0];
// @ts-expect-error actual SFC single mode keeps the scalar constraint
const invalidRoot: RootProps = { modelValue: [date] };
void invalidRoot;
const rootProps: RootProps = {
modelValue: date,
"onUpdate:modelValue": (value) => {
const expected: DateValue | null = value;
// @ts-expect-error event payload is not a string
const invalid: string = value;
void [expected, invalid];
},
};
type CellSlot = Parameters<
NonNullable<InstanceType<typeof CalendarCell>["$slots"]["default"]>
>[0];
const state = {} as CellSlot;
const selected: boolean = state.isSelected;
// @ts-expect-error slot state retains boolean, not any
const invalidSlot: number = state.isSelected;
void [rootProps, selected, invalidSlot];
h(CalendarGrid, grid);
h(CalendarYearPickerCell, { year: 2024 });
void [
single,
multiple,
grid,
cell,
year,
wrong,
wrongMultiple,
mixed,
wrongDate,
wrongGrid,
wrongMode,
];
// @ts-expect-error a year cell requires a numeric year
const missingYear: CalendarYearPickerCellProps = {};
void missingYear;
+63
View File
@@ -0,0 +1,63 @@
import assert from "node:assert/strict";
import fs from "node:fs";
import { createSSRApp, h } from "vue";
import { renderToString } from "@vue/server-renderer";
import { CalendarDate } from "@internationalized/date";
import * as ui from "@heroui-vue/components";
const names = [
"Calendar",
"CalendarRoot",
"CalendarHeader",
"CalendarHeading",
"CalendarNavButton",
"CalendarGrid",
"CalendarGridHeader",
"CalendarGridBody",
"CalendarHeaderCell",
"CalendarCell",
"CalendarCellIndicator",
"CalendarYearPickerTrigger",
"CalendarYearPickerTriggerHeading",
"CalendarYearPickerTriggerIndicator",
"CalendarYearPickerGrid",
"CalendarYearPickerGridBody",
"CalendarYearPickerCell",
];
for (const name of names) assert.ok(ui[name], name);
const html = await renderToString(
createSSRApp({
render: () =>
h(
ui.Calendar,
{
defaultValue: new CalendarDate(2024, 2, 29),
defaultFocusedValue: new CalendarDate(2024, 2, 29),
locale: "en-US",
timeZone: "UTC",
},
() => [
h(ui.CalendarHeading),
h(ui.CalendarGrid, () => [
h(ui.CalendarGridHeader),
h(ui.CalendarGridBody),
]),
h(ui.CalendarYearPickerGrid, () => h(ui.CalendarYearPickerGridBody)),
],
),
}),
);
assert.match(html, /2024-02-29/);
assert.match(html, /data-selected="true"/);
assert.match(html, /February 2024/);
const css = fs.readFileSync(
import.meta.resolve("@heroui-vue/styles/css").replace("file://", ""),
"utf8",
);
for (const token of [
".hv-calendar__cell",
".hv-calendar--week-view",
".hv-calendar--day-view",
".hv-calendar-year-picker__year-cell",
])
assert.ok(css.includes(token), token);
console.log("Calendar independent tarball ESM/Node SSR/CSS passed");