@infinilabs/search-results 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +148 -0
- package/package.json +5 -1
package/README.md
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# @infinilabs/search-results
|
|
2
|
+
|
|
3
|
+
搜索结果列表/宫格展示组件。
|
|
4
|
+
|
|
5
|
+
- 支持列表结果(标题、摘要、面包屑、作者/时间、缩略图、文件类型徽标等)
|
|
6
|
+
- 支持媒体宫格(图片/视频,支持分组、列数、底部动作)
|
|
7
|
+
- 支持 `items` 直接渲染,也支持 `records` 自动转换渲染
|
|
8
|
+
- 支持 `sections` 进行更高级的分组与布局自定义
|
|
9
|
+
|
|
10
|
+
## 安装
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pnpm add @infinilabs/search-results
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
对等依赖(peerDependencies)需要由业务侧提供:
|
|
17
|
+
|
|
18
|
+
- `react`
|
|
19
|
+
- `react-dom`
|
|
20
|
+
|
|
21
|
+
## 使用示例
|
|
22
|
+
|
|
23
|
+
### 1) 基础用法(items)
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import SearchResults, { type SearchResultsItem } from "@infinilabs/search-results";
|
|
27
|
+
|
|
28
|
+
const items: SearchResultsItem[] = [
|
|
29
|
+
{
|
|
30
|
+
type: "result",
|
|
31
|
+
id: "result-0",
|
|
32
|
+
title: "云原生知识检索平台:接入与使用指南",
|
|
33
|
+
href: "https://example.com/docs/search-guide",
|
|
34
|
+
thumbnailUrl: "https://picsum.photos/seed/ai-summary-thumb/320/180",
|
|
35
|
+
fileType: "doc",
|
|
36
|
+
source: "Google",
|
|
37
|
+
description: "AI 摘要:本文档介绍如何配置数据源、设置分类与权限...",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: "imageGroup",
|
|
41
|
+
id: "image-group-1",
|
|
42
|
+
title: "图片",
|
|
43
|
+
columns: 3,
|
|
44
|
+
footerAction: { label: "所有图片 >", href: "#" },
|
|
45
|
+
items: [
|
|
46
|
+
{
|
|
47
|
+
type: "media",
|
|
48
|
+
id: "img-1",
|
|
49
|
+
mediaType: "image",
|
|
50
|
+
title: "云原生技术架构白皮书",
|
|
51
|
+
href: "#",
|
|
52
|
+
thumbnailUrl: "https://picsum.photos/seed/image-group-1/800/600",
|
|
53
|
+
sourceLabel: "Google Drive",
|
|
54
|
+
categoryLabel: "素材",
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
export default function Demo() {
|
|
61
|
+
return <SearchResults items={items} />;
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 2) 使用 records(自动转换)
|
|
66
|
+
|
|
67
|
+
当你的数据更接近后端返回结构时,可以直接传 `records`,组件会将其转换为列表结果并渲染。
|
|
68
|
+
|
|
69
|
+
```tsx
|
|
70
|
+
import SearchResults, { type SearchResultsRecord } from "@infinilabs/search-results";
|
|
71
|
+
|
|
72
|
+
const records: SearchResultsRecord[] = [
|
|
73
|
+
{
|
|
74
|
+
title: "Q3 Business Report",
|
|
75
|
+
url: "https://drive.google.com/file/d/abc123/view",
|
|
76
|
+
summary: "An overview of the company financial performance for Q3.",
|
|
77
|
+
source: { name: "My Hugo Site", id: "e806831dacc3" },
|
|
78
|
+
categories: ["business", "quarterly_reports"],
|
|
79
|
+
thumbnail: "https://picsum.photos/seed/report-thumb/320/180",
|
|
80
|
+
metadata: { file_extension: "pdf" },
|
|
81
|
+
last_updated_by: {
|
|
82
|
+
user: { username: "editor123" },
|
|
83
|
+
timestamp: "2024-11-01T15:30:00Z",
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
export default function Demo() {
|
|
89
|
+
return <SearchResults records={records} />;
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 3) 点击事件(埋点/接管跳转)
|
|
94
|
+
|
|
95
|
+
组件内部触发点击时,会先调用 item 自身的 `onClick`(如果有),再调用 `onItemClick`。
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
import SearchResults, { type SearchResultsItem } from "@infinilabs/search-results";
|
|
99
|
+
|
|
100
|
+
export default function Demo({ items }: { items: SearchResultsItem[] }) {
|
|
101
|
+
return (
|
|
102
|
+
<SearchResults
|
|
103
|
+
items={items}
|
|
104
|
+
onItemClick={(item) => {
|
|
105
|
+
console.log("clicked", item);
|
|
106
|
+
}}
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## 参数说明(Props)
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import type { SearchResultsProps } from "@infinilabs/search-results";
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
| 参数 | 类型 | 说明 |
|
|
119
|
+
|---|---|---|
|
|
120
|
+
| `sections` | `SearchResultsSection[]` | 完全自定义分组与布局;传入后优先使用 |
|
|
121
|
+
| `items` | `SearchResultsItem[]` | 直接传入已归一化的结果项;未传 `sections` 时优先使用 |
|
|
122
|
+
| `records` | `SearchResultsRecord[]` | 原始记录;组件会转换为列表项(`result`)并渲染 |
|
|
123
|
+
| `imageGridColumns` | `2 \| 3 \| 4` | 自动分组时图片/媒体宫格的默认列数 |
|
|
124
|
+
| `className` | `string` | 根容器 class |
|
|
125
|
+
| `onItemClick` | `(item: SearchResultsItem) => void` | 统一点击回调 |
|
|
126
|
+
|
|
127
|
+
优先级规则:
|
|
128
|
+
|
|
129
|
+
- `sections` > `items` > `records`
|
|
130
|
+
|
|
131
|
+
## 类型导出
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import type {
|
|
135
|
+
SearchResultsItem,
|
|
136
|
+
SearchResultsSection,
|
|
137
|
+
SearchResultsRecord,
|
|
138
|
+
SearchResultListItem,
|
|
139
|
+
SearchResultImageItem,
|
|
140
|
+
SearchResultMediaItem,
|
|
141
|
+
SearchResultFileType
|
|
142
|
+
} from "@infinilabs/search-results";
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`SearchResultFileType` 支持:
|
|
146
|
+
|
|
147
|
+
- `pdf` `doc` `ppt` `xls` `link` `word` `text` `unknown`
|
|
148
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infinilabs/search-results",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -53,5 +53,9 @@
|
|
|
53
53
|
"vite": "^7.1.2",
|
|
54
54
|
"vite-plugin-css-injected-by-js": "^3.5.1",
|
|
55
55
|
"vite-plugin-dts": "^3.9.0"
|
|
56
|
+
},
|
|
57
|
+
"repository": {
|
|
58
|
+
"type": "git",
|
|
59
|
+
"url": "https://github.com/infinilabs/ci"
|
|
56
60
|
}
|
|
57
61
|
}
|