feat: migrate Slider with native range semantics and strict ESM declarations
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
# 独立打包消费用例
|
||||
|
||||
`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,所以不能代替此独立产物检查。
|
||||
@@ -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,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