merge: integrate public collection picker migration
# Conflicts: # AGENTS.md # docs/compatibility.md # docs/upstream.md # docs/verification.md # package.json # packages/styles/src/index.ts # packages/vue/src/index.ts # packages/vue/src/types.ts # tests/package/README.md
This commit is contained in:
@@ -37,3 +37,5 @@ COLOR-04 增加 `consume-color-slider-foundation.mjs`,在 `/private/tmp/heroui
|
||||
COLOR-06 增加 `consume-color-field-protocol.mjs`,在 `/private/tmp/heroui-color-field-consumer` 验证两份最终 tarball 的字段/输入组暂存 CSS 与没有提前公开占位;同时保留 Calendar/DateField/Select 的 ESM/SSR/CSS 和 strict NodeNext/bundler 类型正反例。组合字段当前内部实现,其 Props/slots 行为与 SSR/水合在工作区测试;COLOR-07 公共批次须补完整产物契约。
|
||||
|
||||
COLOR-08 增加 `consume-color-picker-protocol.mjs`,最终 tarball 在 `/private/tmp/heroui-color-picker-consumer` 验证 Picker CSS 暂存和没有公共占位,保留旧 Calendar/DateField/Select 运行/SSR/CSS 及双解析模式类型契约。Picker 内部三部件已接入组合夹具,公开批次仍须补完整公共 Props/事件/插槽产物验收。
|
||||
|
||||
B03 使用 `consume-b03-tag-error-message.mjs` / `b03-tag-error-message-contract.ts`,消费者目录 `/private/tmp/heroui-b03-consumer`(pnpm 11 的样式包 override 写在 `pnpm-workspace.yaml`)。验证 ESM 运行时(导出、SSR HTML 契约)、编译产物 CSS 选择器,以及 Tag/TagGroup/TagGroupList/TagRemoveButton/ErrorMessage 的正反类型(bundler 与 NodeNext)。
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
# B01 独立浏览器消费夹具
|
||||
|
||||
用打包产物(`pnpm pack` 生成的 `@heroui-vue/components` / `@heroui-vue/styles` tarball)在独立 Vue 应用中真实挂载,覆盖:
|
||||
|
||||
- `selection`:带 `contain/isolation/overflow:hidden` 祖先的分组级多选长菜单(验证 Portal 脱离裁切、高度上限、真实 `role="menu"` 名称)。
|
||||
- `submenu`:三级子菜单 + 链接型菜单项。
|
||||
- `modal`:Modal 内的 Dropdown(验证层级与关闭顺序、滚动锁释放)。
|
||||
- `standalone`:独立 `Menu` 内联列表(无滚动锁、无浮动定位、不抢焦点)。
|
||||
|
||||
## 使用方式
|
||||
|
||||
```bash
|
||||
# 1. 在库仓库打包
|
||||
pnpm build
|
||||
pnpm --filter @heroui-vue/styles exec pnpm pack --pack-destination /tmp/heroui-b01-consumer
|
||||
pnpm --filter @heroui-vue/components exec pnpm pack --pack-destination /tmp/heroui-b01-consumer
|
||||
|
||||
# 2. 复制本目录到消费工程并安装
|
||||
cp -R tests/package/b01-consumer-app/. /tmp/heroui-b01-consumer/app/
|
||||
cd /tmp/heroui-b01-consumer && pnpm install
|
||||
|
||||
# 3. 打包成静态产物(esbuild 只作为构建工具,运行期仅依赖 tarball)
|
||||
esbuild app/main.js --bundle --format=esm --outfile=app/bundle.js --loader:.css=css
|
||||
|
||||
# 4. 静态服务后打开(`?only=selection|submenu|modal|standalone` 可单例)
|
||||
python3 -m http.server 5199 --bind 127.0.0.1 --directory app
|
||||
```
|
||||
|
||||
`consume-b01-menu-dropdown.mjs` 只做导出/CSS 存在性检查;真实挂载行为以本夹具的浏览器结果为准。
|
||||
@@ -0,0 +1,13 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>B01 consumer</title>
|
||||
<link rel="stylesheet" href="./bundle.css" />
|
||||
<link rel="stylesheet" href="./style.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
<script type="module" src="./bundle.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,253 @@
|
||||
import { createApp, h, ref, defineComponent } from "vue";
|
||||
import {
|
||||
Button,
|
||||
DropdownRoot,
|
||||
DropdownTrigger,
|
||||
DropdownPopover,
|
||||
DropdownMenu,
|
||||
DropdownSection,
|
||||
DropdownItem,
|
||||
DropdownItemIndicator,
|
||||
DropdownSubmenuTrigger,
|
||||
DropdownSubmenuIndicator,
|
||||
Header,
|
||||
Label,
|
||||
Menu,
|
||||
MenuItem,
|
||||
Modal,
|
||||
ModalTrigger,
|
||||
ModalBackdrop,
|
||||
ModalContainer,
|
||||
ModalDialog,
|
||||
ModalHeader,
|
||||
ModalHeading,
|
||||
ModalBody,
|
||||
ModalFooter,
|
||||
ModalCloseTrigger,
|
||||
} from "@heroui-vue/components";
|
||||
import "@heroui-vue/styles/css";
|
||||
|
||||
const selected = ref(["a"]);
|
||||
const actions = [];
|
||||
window.__actions = actions;
|
||||
|
||||
const fruits = ["a", "b", "c", "d", "e", "f", "g", "h"];
|
||||
const names = ["苹果", "香蕉", "樱桃", "橙子", "梨", "葡萄", "西瓜", "芒果"];
|
||||
|
||||
const SelectionCase = defineComponent({
|
||||
name: "SelectionCase",
|
||||
setup() {
|
||||
return () =>
|
||||
h("div", { "data-case": "clipping", class: "clip-ancestor" }, [
|
||||
h(DropdownRoot, { modal: false }, () => [
|
||||
h(DropdownTrigger, null, () =>
|
||||
h(Button, { "aria-label": "水果" }, () => "选择水果"),
|
||||
),
|
||||
h(DropdownPopover, null, () =>
|
||||
h(
|
||||
DropdownMenu,
|
||||
{
|
||||
"aria-label": "水果操作",
|
||||
selectionMode: "multiple",
|
||||
selectedKeys: selected.value,
|
||||
"onUpdate:selectedKeys": (k) => (selected.value = k),
|
||||
},
|
||||
() =>
|
||||
h(DropdownSection, null, () => [
|
||||
h(Header, null, () => "水果"),
|
||||
...fruits.map((id, index) =>
|
||||
h(DropdownItem, { id, textValue: names[index] }, () => [
|
||||
h(DropdownItemIndicator),
|
||||
h(Label, null, () => names[index]),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
]),
|
||||
]);
|
||||
},
|
||||
});
|
||||
|
||||
const SubmenuCase = defineComponent({
|
||||
name: "SubmenuCase",
|
||||
setup() {
|
||||
return () =>
|
||||
h("div", { "data-case": "submenu", class: "case" }, [
|
||||
h(DropdownRoot, { modal: false }, () => [
|
||||
h(DropdownTrigger, null, () =>
|
||||
h(Button, { "aria-label": "分享" }, () => "分享"),
|
||||
),
|
||||
h(DropdownPopover, null, () =>
|
||||
h(
|
||||
DropdownMenu,
|
||||
{ onAction: (k) => actions.push(String(k)) },
|
||||
() => [
|
||||
h(DropdownItem, { id: "copy", textValue: "复制链接" }, () =>
|
||||
h(Label, null, () => "复制链接"),
|
||||
),
|
||||
h(DropdownSubmenuTrigger, null, () => [
|
||||
h(DropdownItem, { id: "more", textValue: "更多" }, () => [
|
||||
h(Label, null, () => "更多"),
|
||||
h(DropdownSubmenuIndicator),
|
||||
]),
|
||||
h(DropdownPopover, null, () =>
|
||||
h(DropdownMenu, null, () => [
|
||||
h(DropdownItem, { id: "wa", textValue: "WhatsApp" }, () =>
|
||||
h(Label, null, () => "WhatsApp"),
|
||||
),
|
||||
h(DropdownItem, { id: "tg", textValue: "Telegram" }, () =>
|
||||
h(Label, null, () => "Telegram"),
|
||||
),
|
||||
h(DropdownSubmenuTrigger, null, () => [
|
||||
h(
|
||||
DropdownItem,
|
||||
{ id: "mail", textValue: "邮件" },
|
||||
() => [
|
||||
h(Label, null, () => "邮件"),
|
||||
h(DropdownSubmenuIndicator),
|
||||
],
|
||||
),
|
||||
h(DropdownPopover, null, () =>
|
||||
h(DropdownMenu, null, () =>
|
||||
h(
|
||||
DropdownItem,
|
||||
{ id: "work", textValue: "工作邮箱" },
|
||||
() => h(Label, null, () => "工作邮箱"),
|
||||
),
|
||||
),
|
||||
),
|
||||
]),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
h(
|
||||
DropdownItem,
|
||||
{ id: "link", textValue: "文档", href: "#docs" },
|
||||
() => h(Label, null, () => "文档链接"),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
]),
|
||||
]);
|
||||
},
|
||||
});
|
||||
|
||||
const ModalCase = defineComponent({
|
||||
name: "ModalCase",
|
||||
setup() {
|
||||
return () =>
|
||||
h("div", { "data-case": "modal", class: "case" }, [
|
||||
h(Modal, null, () => [
|
||||
h(ModalTrigger, null, () => h(Button, null, () => "打开组合复核")),
|
||||
h(ModalBackdrop, null, () =>
|
||||
h(ModalContainer, null, () =>
|
||||
h(ModalDialog, null, () => [
|
||||
h(ModalHeader, null, () =>
|
||||
h(ModalHeading, null, () => "模态内菜单"),
|
||||
),
|
||||
h(ModalBody, null, () => [
|
||||
h(DropdownRoot, { modal: false }, () => [
|
||||
h(DropdownTrigger, null, () =>
|
||||
h(Button, { "aria-label": "菜单" }, () => "菜单"),
|
||||
),
|
||||
h(DropdownPopover, null, () =>
|
||||
h(DropdownMenu, null, () => [
|
||||
h(DropdownItem, { id: "m1", textValue: "一" }, () =>
|
||||
h(Label, null, () => "一"),
|
||||
),
|
||||
h(DropdownItem, { id: "m2", textValue: "二" }, () =>
|
||||
h(Label, null, () => "二"),
|
||||
),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
]),
|
||||
h(ModalFooter, null, () =>
|
||||
h(ModalCloseTrigger, null, () =>
|
||||
h(Button, null, () => "关闭"),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
]),
|
||||
]);
|
||||
},
|
||||
});
|
||||
|
||||
const WrapCase = defineComponent({
|
||||
name: "WrapCase",
|
||||
setup() {
|
||||
return () =>
|
||||
h("div", { "data-case": "wrap", class: "case" }, [
|
||||
h(DropdownRoot, { modal: false }, () => [
|
||||
h(DropdownTrigger, null, () =>
|
||||
h(Button, { "aria-label": "循环" }, () => "循环"),
|
||||
),
|
||||
h(DropdownPopover, null, () =>
|
||||
h(DropdownMenu, null, () =>
|
||||
h(DropdownSubmenuTrigger, null, () => [
|
||||
h(DropdownItem, { id: "wrap-sub", textValue: "子菜单" }, () => [
|
||||
h(Label, null, () => "子菜单"),
|
||||
h(DropdownSubmenuIndicator),
|
||||
]),
|
||||
h(DropdownPopover, null, () =>
|
||||
h(DropdownMenu, { shouldFocusWrap: true }, () => [
|
||||
h(
|
||||
DropdownItem,
|
||||
{ id: "wrap-first", textValue: "First" },
|
||||
() => h(Label, null, () => "First"),
|
||||
),
|
||||
h(
|
||||
DropdownItem,
|
||||
{ id: "wrap-last", textValue: "Last" },
|
||||
() => h(Label, null, () => "Last"),
|
||||
),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
]),
|
||||
]);
|
||||
},
|
||||
});
|
||||
|
||||
const StandaloneCase = defineComponent({
|
||||
name: "StandaloneCase",
|
||||
setup() {
|
||||
return () =>
|
||||
h("div", { "data-case": "standalone", class: "case" }, [
|
||||
h(Menu, { "aria-label": "内联菜单" }, () => [
|
||||
h(MenuItem, { id: "s1" }, () => "内联项一"),
|
||||
h(MenuItem, { id: "s2" }, () => "内联项二"),
|
||||
]),
|
||||
]);
|
||||
},
|
||||
});
|
||||
|
||||
const only = new URLSearchParams(location.search).get("only");
|
||||
const cases = {
|
||||
selection: SelectionCase,
|
||||
submenu: SubmenuCase,
|
||||
modal: ModalCase,
|
||||
standalone: StandaloneCase,
|
||||
wrap: WrapCase,
|
||||
};
|
||||
const shown = only && cases[only] ? [cases[only]] : Object.values(cases);
|
||||
|
||||
createApp(
|
||||
defineComponent({
|
||||
name: "App",
|
||||
setup() {
|
||||
return () =>
|
||||
h(
|
||||
"main",
|
||||
{ style: "display:flex;flex-direction:column;gap:16px;padding:16px" },
|
||||
shown.map((component) => h(component)),
|
||||
);
|
||||
},
|
||||
}),
|
||||
).mount("#app");
|
||||
@@ -0,0 +1,16 @@
|
||||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, "PingFang SC", sans-serif;
|
||||
}
|
||||
.clip-ancestor {
|
||||
overflow: hidden;
|
||||
contain: content;
|
||||
isolation: isolate;
|
||||
height: 64px;
|
||||
border: 1px dashed #bbb;
|
||||
}
|
||||
.case {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
align-items: flex-start;
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
import {
|
||||
DropdownRoot,
|
||||
DropdownTrigger,
|
||||
DropdownPopover,
|
||||
DropdownMenu,
|
||||
DropdownSection,
|
||||
DropdownItem,
|
||||
DropdownItemIndicator,
|
||||
DropdownSubmenuIndicator,
|
||||
DropdownSubmenuTrigger,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuItemIndicator,
|
||||
MenuItemSubmenuIndicator,
|
||||
MenuSection,
|
||||
type DropdownRootProps,
|
||||
type DropdownMenuProps,
|
||||
type DropdownItemProps,
|
||||
type DropdownItemIndicatorProps,
|
||||
type MenuRootProps,
|
||||
type MenuItemProps,
|
||||
type MenuItemIndicatorProps,
|
||||
type MenuSectionProps,
|
||||
type MenuKey,
|
||||
type MenuSelectionMode,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const mode: MenuSelectionMode = "multiple";
|
||||
const keys: MenuKey[] = ["a", 0, ""];
|
||||
|
||||
const root: DropdownRootProps = {
|
||||
trigger: "longPress",
|
||||
longPressDuration: 400,
|
||||
modal: true,
|
||||
dir: "rtl",
|
||||
};
|
||||
// @ts-expect-error unknown trigger mode
|
||||
const badTrigger: DropdownRootProps = { trigger: "hover" };
|
||||
|
||||
const menu: MenuRootProps = {
|
||||
selectionMode: mode,
|
||||
selectedKeys: keys,
|
||||
disabledKeys: ["b"],
|
||||
};
|
||||
// @ts-expect-error selectionMode must be none|single|multiple
|
||||
const badMode: MenuRootProps = { selectionMode: "multiple2" };
|
||||
|
||||
const item: MenuItemProps = {
|
||||
id: "a",
|
||||
textValue: "A",
|
||||
variant: "danger",
|
||||
isDisabled: true,
|
||||
closeOnSelect: false,
|
||||
};
|
||||
// @ts-expect-error variant is default|danger only
|
||||
const badVariant: MenuItemProps = { variant: "primary" };
|
||||
|
||||
const indicator: MenuItemIndicatorProps = { type: "dot" };
|
||||
// @ts-expect-error type is checkmark|dot
|
||||
const badIndicator: MenuItemIndicatorProps = { type: "cross" };
|
||||
|
||||
const section: MenuSectionProps = {
|
||||
selectionMode: "single",
|
||||
selectedKeys: ["x"],
|
||||
};
|
||||
|
||||
const dItem: DropdownItemProps = {
|
||||
id: "x",
|
||||
textValue: "X",
|
||||
variant: "default",
|
||||
};
|
||||
const dInd: DropdownItemIndicatorProps = { type: "checkmark" };
|
||||
const dMenu: DropdownMenuProps = { selectionMode: "none" };
|
||||
|
||||
export const parts = [
|
||||
DropdownRoot,
|
||||
DropdownTrigger,
|
||||
DropdownPopover,
|
||||
DropdownMenu,
|
||||
DropdownSection,
|
||||
DropdownItem,
|
||||
DropdownItemIndicator,
|
||||
DropdownSubmenuIndicator,
|
||||
DropdownSubmenuTrigger,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuItemIndicator,
|
||||
MenuItemSubmenuIndicator,
|
||||
MenuSection,
|
||||
] as const;
|
||||
|
||||
export const values = {
|
||||
root,
|
||||
menu,
|
||||
item,
|
||||
indicator,
|
||||
section,
|
||||
dItem,
|
||||
dInd,
|
||||
dMenu,
|
||||
badTrigger,
|
||||
badMode,
|
||||
badVariant,
|
||||
badIndicator,
|
||||
};
|
||||
@@ -0,0 +1,18 @@
|
||||
import {
|
||||
DropdownItem,
|
||||
DropdownMenu,
|
||||
DropdownSection,
|
||||
} from "@heroui-vue/components";
|
||||
// Valid API values must be accepted by the actual public Vue component types,
|
||||
// not only by separately exported aliases.
|
||||
export const item: InstanceType<typeof DropdownItem>["$props"] = {
|
||||
id: "item",
|
||||
variant: "danger",
|
||||
};
|
||||
export const menu: InstanceType<typeof DropdownMenu>["$props"] = {
|
||||
selectionMode: "multiple",
|
||||
selectedKeys: [0, "0"],
|
||||
};
|
||||
export const section: InstanceType<typeof DropdownSection>["$props"] = {
|
||||
selectionMode: "single",
|
||||
};
|
||||
@@ -0,0 +1,251 @@
|
||||
import { h } from "vue";
|
||||
import {
|
||||
Autocomplete,
|
||||
AutocompleteClearButton,
|
||||
AutocompleteFilter,
|
||||
AutocompleteIndicator,
|
||||
AutocompletePopover,
|
||||
AutocompleteTrigger,
|
||||
AutocompleteValue,
|
||||
ComboBox,
|
||||
ComboBoxInputGroup,
|
||||
ComboBoxPopover,
|
||||
ComboBoxTrigger,
|
||||
ComboBoxValue,
|
||||
ListBox,
|
||||
ListBoxItem,
|
||||
type AutocompleteItem,
|
||||
type AutocompleteProps,
|
||||
type AutocompleteState,
|
||||
type AutocompleteValueState,
|
||||
type AutocompleteValueProps,
|
||||
type ComboBoxItem,
|
||||
type ComboBoxProps,
|
||||
type ComboBoxState,
|
||||
type ComboBoxValueProps,
|
||||
type ComboBoxValueState,
|
||||
type ComboBoxModelValue,
|
||||
type CollectionKey,
|
||||
type ValidateResult,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Keys: numbers and strings stay distinct, null means "no selection".
|
||||
// ---------------------------------------------------------------------------
|
||||
const stringKey: ComboBoxModelValue = "cat";
|
||||
const numericKey: ComboBoxModelValue = 0;
|
||||
const emptyKey: ComboBoxModelValue = "";
|
||||
const cleared: ComboBoxModelValue = null;
|
||||
const multiple: ComboBoxModelValue = ["cat", 0];
|
||||
// @ts-expect-error a key is a string or a finite number
|
||||
const objectKey: ComboBoxModelValue = { id: "cat" };
|
||||
// @ts-expect-error undefined is not a selection state; use null
|
||||
const missingKey: ComboBoxModelValue = undefined;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ComboBox props
|
||||
// ---------------------------------------------------------------------------
|
||||
const comboProps: ComboBoxProps = {
|
||||
modelValue: stringKey,
|
||||
defaultValue: numericKey,
|
||||
selectionMode: "multiple",
|
||||
inputValue: "",
|
||||
defaultInputValue: "",
|
||||
items: [{ id: 0, textValue: "Zero", isDisabled: false }],
|
||||
disabledKeys: ["a", 0, ""],
|
||||
open: false,
|
||||
defaultOpen: false,
|
||||
isDisabled: false,
|
||||
isReadOnly: false,
|
||||
isRequired: false,
|
||||
isInvalid: false,
|
||||
allowsCustomValue: true,
|
||||
allowsEmptyCollection: true,
|
||||
menuTrigger: "manual",
|
||||
shouldFocusWrap: true,
|
||||
fullWidth: true,
|
||||
variant: "secondary",
|
||||
name: "animal",
|
||||
form: "external-form",
|
||||
formValue: "text",
|
||||
autoComplete: "off",
|
||||
autoFocus: true,
|
||||
validationBehavior: "aria",
|
||||
placeholder: "Select an item",
|
||||
as: "section",
|
||||
asChild: false,
|
||||
class: ["hv-combo-box", { "is-dense": true }],
|
||||
};
|
||||
// @ts-expect-error selectionMode is a closed union
|
||||
const badMode: ComboBoxProps = { selectionMode: "triple" };
|
||||
// @ts-expect-error variant is a closed union
|
||||
const badVariant: ComboBoxProps = { variant: "tertiary" };
|
||||
// @ts-expect-error formValue only allows key or text
|
||||
const badFormValue: ComboBoxProps = { formValue: "both" };
|
||||
|
||||
// `validate` keeps its parameter and result types.
|
||||
const comboWithValidate: ComboBoxProps = {
|
||||
validate: (value) => {
|
||||
const accepted: ComboBoxModelValue = value;
|
||||
void accepted;
|
||||
return true;
|
||||
},
|
||||
};
|
||||
// @ts-expect-error validate must return a validation result, not a boolean flag object
|
||||
const badValidate: ComboBoxProps = { validate: () => ({ ok: true }) };
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Autocomplete props, including the source `items` mapping
|
||||
// ---------------------------------------------------------------------------
|
||||
const autocompleteItems: AutocompleteItem[] = [
|
||||
{ id: "california", textValue: "California" },
|
||||
{ id: 0, textValue: "Zero", isDisabled: true },
|
||||
];
|
||||
// @ts-expect-error items need a textValue for filtering and display
|
||||
const itemsWithoutText: AutocompleteItem[] = [{ id: "a" }];
|
||||
|
||||
const autocompleteProps: AutocompleteProps = {
|
||||
modelValue: cleared,
|
||||
value: multiple,
|
||||
defaultValue: ["a", "b"],
|
||||
items: autocompleteItems,
|
||||
selectionMode: "multiple",
|
||||
disabledKeys: ["a"],
|
||||
open: true,
|
||||
isOpen: true,
|
||||
defaultOpen: false,
|
||||
isDisabled: false,
|
||||
isRequired: true,
|
||||
isInvalid: false,
|
||||
allowsEmptyCollection: false,
|
||||
placeholder: "Select an item",
|
||||
name: "state",
|
||||
form: "external-form",
|
||||
fullWidth: true,
|
||||
variant: "primary",
|
||||
validationBehavior: "native",
|
||||
as: "div",
|
||||
asChild: true,
|
||||
validate: (value): ValidateResult => (Array.isArray(value) ? true : null),
|
||||
};
|
||||
const badAutocompleteValidate: AutocompleteProps = {
|
||||
// @ts-expect-error validate must not widen to an arbitrary return type
|
||||
validate: () => Symbol("nope"),
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Events keep their payload types
|
||||
// ---------------------------------------------------------------------------
|
||||
const comboEvents = h(ComboBox, {
|
||||
"onUpdate:modelValue": (value: ComboBoxModelValue) => void value,
|
||||
onChange: (value: ComboBoxModelValue) => void value,
|
||||
"onUpdate:selectedKey": (key: CollectionKey | null) => void key,
|
||||
selectionChange: (key: CollectionKey | null) => void key,
|
||||
"onUpdate:inputValue": (text: string) => void text,
|
||||
inputChange: (text: string) => void text,
|
||||
"onUpdate:open": (open: boolean) => void open,
|
||||
openChange: (open: boolean) => void open,
|
||||
});
|
||||
const badComboEvent = h(ComboBox, {
|
||||
// @ts-expect-error the model event carries the value, never the input text
|
||||
"onUpdate:modelValue": (text: string) => void text,
|
||||
});
|
||||
|
||||
// Root scoped slots expose the open/selection state.
|
||||
const comboState = (state: ComboBoxState): string =>
|
||||
`${state.isOpen}:${state.inputValue}:${state.selectedKeys.length}`;
|
||||
const autocompleteState = (state: AutocompleteState): string =>
|
||||
`${state.isOpen}:${state.selectedKeys.length}`;
|
||||
const comboValueState = (state: ComboBoxValueState): string =>
|
||||
`${state.isPlaceholder}:${state.selectedItems.length}`;
|
||||
|
||||
const autocompleteEvents = h(Autocomplete, {
|
||||
"onUpdate:modelValue": (value: ComboBoxModelValue) => void value,
|
||||
onChange: (value: ComboBoxModelValue) => void value,
|
||||
"onUpdate:open": (open: boolean) => void open,
|
||||
openChange: (open: boolean) => void open,
|
||||
clear: () => undefined,
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Parts: every public part accepts the documented props and slots
|
||||
// ---------------------------------------------------------------------------
|
||||
const comboTree = h(ComboBox, { "aria-label": "动物" }, () => [
|
||||
h(ComboBoxInputGroup, { class: "w-full" }, () => "input"),
|
||||
h(ComboBoxValue, { placeholder: "未选择" }),
|
||||
h(ComboBoxPopover, { placement: "top", offset: 4, shouldFlip: false }, () =>
|
||||
h(ListBox, { "aria-label": "动物" }, () =>
|
||||
h(ListBoxItem, { id: 0, textValue: "Zero" }, () => "Zero"),
|
||||
),
|
||||
),
|
||||
h(ComboBoxTrigger, { isDisabled: true }),
|
||||
]);
|
||||
// @ts-expect-error placement is a closed union
|
||||
const badPlacement = h(ComboBoxPopover, { placement: "middle" });
|
||||
|
||||
const autocompleteTree = h(Autocomplete, { "aria-label": "州" }, () => [
|
||||
h(AutocompleteTrigger, { isDisabled: false }, () => [
|
||||
h(AutocompleteValue, null, {
|
||||
// Scoped slot state keeps its documented, exported shape.
|
||||
default: (state: AutocompleteValueState) => {
|
||||
const placeholder: boolean = state.isPlaceholder;
|
||||
const joined: string = state.selectedText || state.defaultChildren;
|
||||
const keys = state.selectedItems.map((item) => item.key);
|
||||
return placeholder ? joined : keys.join(",");
|
||||
},
|
||||
}),
|
||||
h(AutocompleteClearButton),
|
||||
h(AutocompleteIndicator),
|
||||
]),
|
||||
h(AutocompletePopover, { placement: "bottom end" }, () =>
|
||||
h(
|
||||
AutocompleteFilter,
|
||||
{ filter: (text, input) => text.includes(input) },
|
||||
() =>
|
||||
h(ListBox, null, () =>
|
||||
h(ListBoxItem, { id: "a", textValue: "A" }, () => "A"),
|
||||
),
|
||||
),
|
||||
),
|
||||
]);
|
||||
|
||||
const valueProps: ComboBoxValueProps = { placeholder: "未选择" };
|
||||
const autocompleteValueProps: AutocompleteValueProps = {};
|
||||
// @ts-expect-error ComboBoxValue has no `items` prop
|
||||
const badValueProps: ComboBoxValueProps = { items: [] };
|
||||
|
||||
const item: ComboBoxItem = { id: 0, textValue: "Zero" };
|
||||
const autocompleteFirstItem: AutocompleteItem = autocompleteItems[0]!;
|
||||
|
||||
export {
|
||||
comboState,
|
||||
comboValueState,
|
||||
autocompleteState,
|
||||
autocompleteEvents,
|
||||
autocompleteFirstItem,
|
||||
autocompleteProps,
|
||||
autocompleteTree,
|
||||
autocompleteValueProps,
|
||||
badAutocompleteValidate,
|
||||
badComboEvent,
|
||||
badFormValue,
|
||||
badMode,
|
||||
badPlacement,
|
||||
badValidate,
|
||||
badValueProps,
|
||||
badVariant,
|
||||
cleared,
|
||||
comboEvents,
|
||||
comboProps,
|
||||
comboTree,
|
||||
comboWithValidate,
|
||||
emptyKey,
|
||||
item,
|
||||
itemsWithoutText,
|
||||
missingKey,
|
||||
multiple,
|
||||
numericKey,
|
||||
objectKey,
|
||||
stringKey,
|
||||
valueProps,
|
||||
};
|
||||
@@ -0,0 +1,121 @@
|
||||
import { h } from "vue";
|
||||
import {
|
||||
ErrorMessage,
|
||||
Tag,
|
||||
TagGroup,
|
||||
TagGroupList,
|
||||
TagRemoveButton,
|
||||
type TagGroupProps,
|
||||
type TagGroupListProps,
|
||||
type TagKey,
|
||||
type TagProps,
|
||||
type TagRemoveButtonProps,
|
||||
type TagRenderState,
|
||||
type ErrorMessageProps,
|
||||
} from "@heroui-vue/components";
|
||||
|
||||
const key: TagKey = "news";
|
||||
const numericKey: TagKey = 0;
|
||||
// @ts-expect-error collection keys are strings or finite numbers
|
||||
const invalidKey: TagKey = {};
|
||||
|
||||
const groupProps: TagGroupProps = {
|
||||
selectionMode: "multiple",
|
||||
modelValue: [key, numericKey],
|
||||
defaultValue: [],
|
||||
disabledKeys: [key],
|
||||
isDisabled: false,
|
||||
disallowEmptySelection: true,
|
||||
size: "lg",
|
||||
variant: "surface",
|
||||
dir: "rtl",
|
||||
as: "section",
|
||||
asChild: false,
|
||||
};
|
||||
// @ts-expect-error selectionMode is a closed union
|
||||
const badMode: TagGroupProps = { selectionMode: "triple" };
|
||||
// @ts-expect-error size is a closed union
|
||||
const badSize: TagGroupProps = { size: "xl" };
|
||||
|
||||
// `items` keeps the caller's item type: extra fields are allowed and reach the
|
||||
// scoped slot unchanged.
|
||||
const listProps: TagGroupListProps<{ id: string; name: string }> = {
|
||||
items: [{ id: "a", name: "A" }],
|
||||
as: "div",
|
||||
};
|
||||
// @ts-expect-error items must carry a collection key
|
||||
const listPropsWithoutId: TagGroupListProps<{ name: string }> = {
|
||||
items: [{ name: "A" }],
|
||||
};
|
||||
|
||||
const tagProps: TagProps = { id: key, textValue: "资讯", isDisabled: false };
|
||||
const removeProps: TagRemoveButtonProps = {
|
||||
textValue: "资讯",
|
||||
isDisabled: true,
|
||||
};
|
||||
// ErrorMessage declares no props of its own: content, `id` and `class` are
|
||||
// ordinary attributes / slots.
|
||||
const messageProps: ErrorMessageProps = {};
|
||||
|
||||
const state: TagRenderState = {
|
||||
isSelected: true,
|
||||
isDisabled: false,
|
||||
isHovered: false,
|
||||
isPressed: false,
|
||||
isFocused: true,
|
||||
isFocusVisible: true,
|
||||
allowsRemoving: true,
|
||||
};
|
||||
|
||||
const tree = h(
|
||||
TagGroup,
|
||||
{
|
||||
selectionMode: "single",
|
||||
modelValue: [key],
|
||||
"onUpdate:modelValue": (keys: TagKey[]) => keys.length,
|
||||
onSelectionChange: (keys: TagKey[]) => keys,
|
||||
onRemove: (keys: TagKey[]) => keys,
|
||||
},
|
||||
{
|
||||
default: () => [
|
||||
h(TagGroupList, null, {
|
||||
default: () =>
|
||||
h(
|
||||
Tag,
|
||||
{ id: key },
|
||||
{
|
||||
default: (tagState: TagRenderState) =>
|
||||
tagState.isSelected ? "selected" : "tag",
|
||||
},
|
||||
),
|
||||
empty: () =>
|
||||
h(ErrorMessage, { ...messageProps, id: "error" }, () => "empty"),
|
||||
}),
|
||||
h(Tag, tagProps, {
|
||||
default: () => [
|
||||
"资讯",
|
||||
h(TagRemoveButton, removeProps, { default: () => "x" }),
|
||||
],
|
||||
}),
|
||||
h(ErrorMessage, null, () => "请选择"),
|
||||
],
|
||||
},
|
||||
);
|
||||
|
||||
// @ts-expect-error Tag requires a collection key
|
||||
const missingId = h(Tag, {});
|
||||
|
||||
// @ts-expect-error remove button text must be a string
|
||||
const badRemoveText = h(TagRemoveButton, { textValue: 1 });
|
||||
|
||||
void [
|
||||
listPropsWithoutId,
|
||||
invalidKey,
|
||||
badMode,
|
||||
badSize,
|
||||
state,
|
||||
tree,
|
||||
missingId,
|
||||
badRemoveText,
|
||||
groupProps,
|
||||
];
|
||||
@@ -0,0 +1,63 @@
|
||||
/**
|
||||
* Independent ESM/CSS consumption for B01 Menu/Dropdown.
|
||||
* Copy into a fresh consumer that installs packed tarballs (no source alias).
|
||||
*/
|
||||
import { readFileSync } from "node:fs";
|
||||
|
||||
const mod = await import("@heroui-vue/components");
|
||||
const {
|
||||
DropdownRoot,
|
||||
DropdownTrigger,
|
||||
DropdownPopover,
|
||||
DropdownMenu,
|
||||
DropdownItem,
|
||||
DropdownItemIndicator,
|
||||
DropdownSubmenuTrigger,
|
||||
DropdownSubmenuIndicator,
|
||||
DropdownSection,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuItemIndicator,
|
||||
MenuItemSubmenuIndicator,
|
||||
MenuSection,
|
||||
} = mod;
|
||||
|
||||
const expected = {
|
||||
DropdownRoot,
|
||||
DropdownTrigger,
|
||||
DropdownPopover,
|
||||
DropdownMenu,
|
||||
DropdownItem,
|
||||
DropdownItemIndicator,
|
||||
DropdownSubmenuTrigger,
|
||||
DropdownSubmenuIndicator,
|
||||
DropdownSection,
|
||||
Menu,
|
||||
MenuItem,
|
||||
MenuItemIndicator,
|
||||
MenuItemSubmenuIndicator,
|
||||
MenuSection,
|
||||
};
|
||||
for (const [name, value] of Object.entries(expected)) {
|
||||
if (!value) {
|
||||
console.error("missing export", name);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
const cssPath = import.meta.resolve("@heroui-vue/styles/css");
|
||||
const css = readFileSync(new URL(cssPath), "utf8");
|
||||
for (const token of [
|
||||
"hv-menu-item",
|
||||
"hv-menu-item__indicator--submenu",
|
||||
"hv-dropdown__popover",
|
||||
"hv-dropdown__menu",
|
||||
"data-selected",
|
||||
]) {
|
||||
if (!css.includes(token)) {
|
||||
console.error("css missing", token);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
console.log("b01 menu/dropdown ESM+CSS consume ok");
|
||||
@@ -0,0 +1,159 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { createSSRApp, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import * as lib from "@heroui-vue/components";
|
||||
|
||||
for (const name of [
|
||||
"ComboBox",
|
||||
"ComboBoxInputGroup",
|
||||
"ComboBoxTrigger",
|
||||
"ComboBoxValue",
|
||||
"ComboBoxPopover",
|
||||
"Autocomplete",
|
||||
"AutocompleteTrigger",
|
||||
"AutocompleteValue",
|
||||
"AutocompleteIndicator",
|
||||
"AutocompleteClearButton",
|
||||
"AutocompletePopover",
|
||||
"AutocompleteFilter",
|
||||
"comboBoxVariants",
|
||||
"autocompleteVariants",
|
||||
])
|
||||
assert(lib[name], name);
|
||||
|
||||
const items = [
|
||||
{ id: "cat", textValue: "猫" },
|
||||
{ id: "dog", textValue: "狗" },
|
||||
];
|
||||
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h("main", [
|
||||
h(
|
||||
lib.ComboBox,
|
||||
{ "aria-label": "动物", defaultSelectedKey: "cat", name: "animal" },
|
||||
{
|
||||
default: () => [
|
||||
h(lib.Label, null, () => "动物"),
|
||||
h(lib.ComboBoxInputGroup, null, {
|
||||
default: () => [h(lib.Input, {}), h(lib.ComboBoxTrigger)],
|
||||
}),
|
||||
h(lib.ComboBoxPopover, null, {
|
||||
default: () =>
|
||||
h(lib.ListBox, null, {
|
||||
default: () =>
|
||||
items.map((item) =>
|
||||
h(
|
||||
lib.ListBoxItem,
|
||||
{
|
||||
id: item.id,
|
||||
key: item.id,
|
||||
textValue: item.textValue,
|
||||
},
|
||||
() => item.textValue,
|
||||
),
|
||||
),
|
||||
}),
|
||||
}),
|
||||
],
|
||||
},
|
||||
),
|
||||
h(
|
||||
lib.Autocomplete,
|
||||
{ "aria-label": "州", name: "state", defaultValue: "dog" },
|
||||
{
|
||||
default: () => [
|
||||
h(lib.AutocompleteTrigger, null, {
|
||||
default: () => [
|
||||
h(lib.AutocompleteValue),
|
||||
h(lib.AutocompleteClearButton),
|
||||
h(lib.AutocompleteIndicator),
|
||||
],
|
||||
}),
|
||||
h(lib.AutocompletePopover, null, {
|
||||
default: () =>
|
||||
h(lib.AutocompleteFilter, null, {
|
||||
default: () => [
|
||||
h(
|
||||
lib.SearchField,
|
||||
{ "aria-label": "搜索" },
|
||||
{
|
||||
default: () =>
|
||||
h(lib.SearchFieldGroup, null, {
|
||||
default: () => [h(lib.SearchFieldInput)],
|
||||
}),
|
||||
},
|
||||
),
|
||||
h(lib.ListBox, null, {
|
||||
default: () =>
|
||||
items.map((item) =>
|
||||
h(
|
||||
lib.ListBoxItem,
|
||||
{
|
||||
id: item.id,
|
||||
key: item.id,
|
||||
textValue: item.textValue,
|
||||
},
|
||||
() => item.textValue,
|
||||
),
|
||||
),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
}),
|
||||
],
|
||||
},
|
||||
),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
|
||||
assert(html.includes('data-slot="combo-box"'), "combo-box root");
|
||||
assert(html.includes('role="combobox"'), "combobox input role");
|
||||
assert(html.includes('data-slot="combo-box-trigger"'), "combo box trigger");
|
||||
assert(html.includes('name="animal"'), "combo box form name");
|
||||
assert(html.includes('data-slot="autocomplete"'), "autocomplete root");
|
||||
assert(
|
||||
html.includes('data-slot="autocomplete-trigger"'),
|
||||
"autocomplete trigger",
|
||||
);
|
||||
assert(html.includes('role="button"'), "autocomplete trigger is a button");
|
||||
assert(html.includes('name="state"'), "autocomplete form name");
|
||||
assert(html.includes("猫"), "combo box preselected label");
|
||||
|
||||
const css = readFileSync(
|
||||
"node_modules/@heroui-vue/styles/dist/styles.css",
|
||||
"utf8",
|
||||
);
|
||||
for (const rule of [
|
||||
".hv-combo-box",
|
||||
".hv-combo-box__input-group",
|
||||
".hv-combo-box__trigger",
|
||||
".hv-combo-box__popover",
|
||||
".hv-combo-box__value",
|
||||
".hv-autocomplete",
|
||||
".hv-autocomplete__trigger",
|
||||
".hv-autocomplete__value",
|
||||
".hv-autocomplete__indicator",
|
||||
".hv-autocomplete__clear-button",
|
||||
".hv-autocomplete__popover",
|
||||
".hv-autocomplete--secondary",
|
||||
])
|
||||
assert(css.includes(rule), `missing CSS ${rule}`);
|
||||
|
||||
assert(
|
||||
lib
|
||||
.comboBoxVariants({ fullWidth: true })
|
||||
.base()
|
||||
.includes("hv-combo-box--full-width"),
|
||||
);
|
||||
assert(
|
||||
lib
|
||||
.autocompleteVariants({ variant: "secondary" })
|
||||
.base()
|
||||
.includes("hv-autocomplete--secondary"),
|
||||
);
|
||||
|
||||
console.log("B02 pickers consumption OK");
|
||||
@@ -0,0 +1,88 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { createSSRApp, h } from "vue";
|
||||
import { renderToString } from "@vue/server-renderer";
|
||||
import * as lib from "@heroui-vue/components";
|
||||
|
||||
for (const name of [
|
||||
"TagGroup",
|
||||
"TagGroupList",
|
||||
"Tag",
|
||||
"TagRemoveButton",
|
||||
"ErrorMessage",
|
||||
"tagVariants",
|
||||
"tagGroupVariants",
|
||||
"errorMessageVariants",
|
||||
])
|
||||
assert(lib[name], name);
|
||||
|
||||
const html = await renderToString(
|
||||
createSSRApp({
|
||||
render: () =>
|
||||
h(
|
||||
lib.TagGroup,
|
||||
{
|
||||
"aria-label": "分类",
|
||||
selectionMode: "multiple",
|
||||
modelValue: ["news"],
|
||||
onRemove: () => {},
|
||||
},
|
||||
{
|
||||
default: () => [
|
||||
h(lib.TagGroupList, null, {
|
||||
default: () => [
|
||||
h(lib.Tag, { id: "news" }, { default: () => "资讯" }),
|
||||
h(
|
||||
lib.Tag,
|
||||
{ id: 0, isDisabled: true },
|
||||
{ default: () => "零" },
|
||||
),
|
||||
],
|
||||
}),
|
||||
h(lib.ErrorMessage, null, { default: () => "请至少选择一项" }),
|
||||
],
|
||||
},
|
||||
),
|
||||
}),
|
||||
);
|
||||
|
||||
assert(html.includes('role="grid"'), "grid role on the list");
|
||||
assert(html.includes('aria-label="分类"'), "grid carries the group label");
|
||||
assert(html.includes('aria-multiselectable="true"'), "multiple selection flag");
|
||||
assert(html.includes('role="row"'), "rows for tags");
|
||||
assert(html.includes('aria-selected="true"'), "accepted selection");
|
||||
assert(html.includes('aria-disabled="true"'), "disabled tag");
|
||||
assert(html.includes("Remove tag 资讯"), "composed remove button name");
|
||||
assert(html.includes('data-slot="tag-remove-button"'), "remove button slot");
|
||||
assert(html.includes('data-slot="error-message"'), "error message slot");
|
||||
assert(html.includes('slot="errorMessage"'), "baseline error message marker");
|
||||
|
||||
const css = readFileSync(
|
||||
"node_modules/@heroui-vue/styles/dist/styles.css",
|
||||
"utf8",
|
||||
);
|
||||
for (const rule of [
|
||||
".hv-tag",
|
||||
".hv-tag--sm",
|
||||
".hv-tag--lg",
|
||||
".hv-tag--surface",
|
||||
".hv-tag__remove-button",
|
||||
".hv-tag-group",
|
||||
".hv-tag-group__list",
|
||||
".hv-error-message",
|
||||
])
|
||||
assert(css.includes(rule), `missing CSS rule ${rule}`);
|
||||
// The list padding rule must survive minification for Description/ErrorMessage.
|
||||
assert(
|
||||
/\.hv-tag-group\s*\[data-slot=["']?error-message/.test(css),
|
||||
"missing tag-group error-message padding rule",
|
||||
);
|
||||
|
||||
assert.equal(typeof lib.tagVariants({ size: "sm" }).base, "function");
|
||||
assert(lib.tagVariants({ size: "sm" }).base().includes("hv-tag--sm"));
|
||||
assert(
|
||||
lib.tagVariants({ variant: "surface" }).base().includes("hv-tag--surface"),
|
||||
);
|
||||
assert(lib.errorMessageVariants().includes("hv-error-message"));
|
||||
|
||||
console.log("B03 tag/error-message consumption OK");
|
||||
Reference in New Issue
Block a user