merge: integrate reviewed M30-M32 with NumberField Slider and migration lessons
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
# 独立打包消费用例
|
||||
|
||||
`consume-slider.mjs` 和 `slider-contract.ts` 应复制到工作区之外的全新 Vue 工程运行,依赖安装使用 `pnpm pack` 生成的两个 tarball,不设置指向源码的 paths/alias。private 样式包通过 pnpm overrides 指向本地样式 tarball。
|
||||
|
||||
库构建与打包后,在消费工程执行:
|
||||
|
||||
```sh
|
||||
node consume-slider.mjs
|
||||
pnpm exec tsc --noEmit --strict --skipLibCheck --module nodenext --moduleResolution nodenext --target es2022 slider-contract.ts
|
||||
pnpm exec tsc --noEmit --strict --skipLibCheck --module esnext --moduleResolution bundler --target es2022 slider-contract.ts
|
||||
```
|
||||
|
||||
`@ts-expect-error` 必须实际生效;出现 unused 指令是失败,不得删除反例。数字字段的 validate 参数也必须保留推断类型。`skipLibCheck` 只略过依赖内部诊断,不略过这些消费端反例。
|
||||
|
||||
SLIDER-01 已在 `/private/tmp/heroui-slider-consumer` 完成上述检查,临时契约文件名为 `contract.ts`。默认工作区 typecheck 仍使用源码 alias,所以不能代替此独立产物检查。
|
||||
|
||||
M30–M32 增加 consume-m30-m32.mjs 和 m30-m32-contract.ts。将它们复制到同一个独立消费工程,执行运行脚本,并将契约文件加入上述两种 tsc 命令。合并后的产物还应同时通过原 NumberField/Slider 消费检查,避免只验证新加组件。
|
||||
@@ -0,0 +1,49 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { createSSRApp, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import {
|
||||
InputOTP,
|
||||
InputOTPGroup,
|
||||
InputOTPSlot,
|
||||
Label,
|
||||
Header,
|
||||
Pagination,
|
||||
PaginationContent,
|
||||
PaginationItem,
|
||||
PaginationLink,
|
||||
} from "@heroui-vue/components";
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h("div", [
|
||||
h(Header, {}, () => "Heading"),
|
||||
h(Pagination, {}, () =>
|
||||
h(PaginationContent, {}, () =>
|
||||
h(PaginationItem, {}, () =>
|
||||
h(PaginationLink, { "aria-current": "step" }, () => "1"),
|
||||
),
|
||||
),
|
||||
),
|
||||
h(InputOTP, { maxLength: 2, defaultValue: "12", name: "code" }, () => [
|
||||
h(Label, { id: "consumer-label" }, () => "Security code"),
|
||||
h(InputOTPGroup, {}, () => [
|
||||
h(InputOTPSlot, { index: 0 }),
|
||||
h(InputOTPSlot, { index: 1 }),
|
||||
]),
|
||||
]),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
assert(html.includes('data-slot="header"'));
|
||||
assert(html.includes('aria-current="step"'));
|
||||
assert.equal(html.match(/aria-labelledby="consumer-label"/g)?.length, 2);
|
||||
assert(html.includes('value="12"'));
|
||||
assert(html.includes('name="code"'));
|
||||
const css = readFileSync(
|
||||
new URL(import.meta.resolve("@heroui-vue/styles/css")),
|
||||
"utf8",
|
||||
);
|
||||
for (const name of ["hv-header", "hv-pagination", "hv-input-otp"])
|
||||
assert(css.includes(name));
|
||||
console.log("M30–M32 independent tarball ESM/SSR/ARIA/CSS passed.");
|
||||
@@ -0,0 +1,45 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { createSSRApp, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import {
|
||||
Slider,
|
||||
SliderTrack,
|
||||
SliderFill,
|
||||
SliderThumb,
|
||||
SliderOutput,
|
||||
SliderMarks,
|
||||
Label,
|
||||
sliderVariants,
|
||||
} from "@heroui-vue/components";
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h(Slider, { defaultValue: [20, 80], dir: "rtl" }, () => [
|
||||
h(Label, {}, () => "Price"),
|
||||
h(SliderOutput),
|
||||
h(SliderTrack, {}, () => [
|
||||
h(SliderFill),
|
||||
h(SliderThumb, { name: "min" }),
|
||||
h(SliderThumb, { name: "max", index: 1 }),
|
||||
]),
|
||||
h(SliderMarks),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
assert(html.includes('aria-valuenow="20"'));
|
||||
assert(html.includes('aria-valuenow="80"'));
|
||||
assert(html.includes("right:20%"));
|
||||
assert(html.includes('name="min"'));
|
||||
assert(html.includes('name="max"'));
|
||||
const css = readFileSync(
|
||||
new URL(import.meta.resolve("@heroui-vue/styles/css")),
|
||||
"utf8",
|
||||
);
|
||||
assert(css.includes(".hv-slider__track"));
|
||||
assert(css.includes("prefers-reduced-motion"));
|
||||
assert(!css.includes(".hv-slider__thumb:after:not(:is())"));
|
||||
assert(sliderVariants().thumb().includes("hv-slider__thumb"));
|
||||
console.log(
|
||||
"Independent tarball consumer: ESM, SSR, CSS and six named parts passed.",
|
||||
);
|
||||
@@ -0,0 +1,19 @@
|
||||
import {
|
||||
type InputOTPProps,
|
||||
type PaginationProps,
|
||||
type HeaderProps,
|
||||
} from "@heroui-vue/components";
|
||||
const input: InputOTPProps = {
|
||||
maxLength: 4,
|
||||
modelValue: "1234",
|
||||
variant: "secondary",
|
||||
};
|
||||
const pager: PaginationProps = { size: "sm" };
|
||||
const heading: HeaderProps = { as: "header" };
|
||||
// @ts-expect-error public OTP values are strings
|
||||
const wrongModel: InputOTPProps = { maxLength: 4, modelValue: 1234 };
|
||||
// @ts-expect-error unsupported OTP variant
|
||||
const wrongVariant: InputOTPProps = { maxLength: 4, variant: "ghost" };
|
||||
// @ts-expect-error Pagination has a fixed size set
|
||||
const wrongSize: PaginationProps = { size: "xl" };
|
||||
void [input, pager, heading, wrongModel, wrongVariant, wrongSize];
|
||||
@@ -0,0 +1,24 @@
|
||||
import {
|
||||
type SliderProps,
|
||||
type SliderThumbProps,
|
||||
Slider,
|
||||
SliderTrack,
|
||||
SliderThumb,
|
||||
} from "@heroui-vue/components";
|
||||
const valid: SliderProps = { modelValue: [20, 80], orientation: "vertical" };
|
||||
const thumb: SliderThumbProps = { name: "max", index: 1, isDisabled: true };
|
||||
// @ts-expect-error model is numeric
|
||||
const invalid: SliderProps = { modelValue: "20" };
|
||||
// @ts-expect-error orientation is constrained
|
||||
const direction: SliderProps = { orientation: "diagonal" };
|
||||
void [valid, thumb, invalid, direction, Slider, SliderTrack, SliderThumb];
|
||||
import { type NumberFieldProps } from "@heroui-vue/components";
|
||||
const numeric: NumberFieldProps = {
|
||||
modelValue: null,
|
||||
validate: (value) => (value === null ? "Required" : true),
|
||||
};
|
||||
// @ts-expect-error NumberField public values must remain numeric in NodeNext too
|
||||
const badNumeric: NumberFieldProps = { modelValue: "12,5" };
|
||||
// @ts-expect-error index is numeric
|
||||
const badThumb: SliderThumbProps = { index: "1" };
|
||||
void [numeric, badNumeric, badThumb];
|
||||
Reference in New Issue
Block a user