@talex-touch/utils 1.0.37 → 1.0.39

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talex-touch/utils",
3
- "version": "1.0.37",
3
+ "version": "1.0.39",
4
4
  "private": false,
5
5
  "description": "Tuff series utils",
6
6
  "author": "TalexDreamSoul",
@@ -1,4 +1,4 @@
1
- import type { PluginClipboardHistoryResponse, PluginClipboardItem } from './types'
1
+ import type { PluginClipboardHistoryResponse, PluginClipboardItem, PluginClipboardSearchOptions, PluginClipboardSearchResponse } from './types'
2
2
 
3
3
  function ensurePluginChannel() {
4
4
  const channel = (window as any)?.$channel
@@ -23,9 +23,7 @@ function normalizeItem(item: PluginClipboardItem | null): PluginClipboardItem |
23
23
  return item
24
24
  }
25
25
 
26
- export interface ClipboardHistoryOptions {
27
- page?: number
28
- }
26
+ export type ClipboardHistoryOptions = PluginClipboardSearchOptions
29
27
 
30
28
  export interface ClipboardFavoriteOptions {
31
29
  id: number
@@ -46,6 +44,9 @@ export interface ClipboardApplyOptions {
46
44
  type?: PluginClipboardItem['type']
47
45
  }
48
46
 
47
+ export type ClipboardSearchOptions = PluginClipboardSearchOptions
48
+ export type ClipboardSearchResponse = PluginClipboardSearchResponse
49
+
49
50
  export function useClipboardHistory() {
50
51
  const channel = ensurePluginChannel()
51
52
 
@@ -56,8 +57,7 @@ export function useClipboardHistory() {
56
57
  },
57
58
 
58
59
  async getHistory(options: ClipboardHistoryOptions = {}): Promise<PluginClipboardHistoryResponse> {
59
- const { page = 1 } = options
60
- const response = await channel.send('clipboard:get-history', { page })
60
+ const response = await channel.send('clipboard:get-history', options)
61
61
  const history = Array.isArray(response?.history)
62
62
  ? response.history.map((item: PluginClipboardItem) => normalizeItem(item) ?? item)
63
63
  : []
@@ -79,6 +79,44 @@ export function useClipboardHistory() {
79
79
  await channel.send('clipboard:clear-history')
80
80
  },
81
81
 
82
+ /**
83
+ * Search clipboard history with advanced filtering options.
84
+ * Supports keyword search, time-based filtering, and combined filters.
85
+ *
86
+ * @param options - Search options
87
+ * @returns Search results with pagination metadata
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * // Search by keyword
92
+ * const result = await searchHistory({ keyword: 'hello' })
93
+ *
94
+ * // Search by time range (last 24 hours)
95
+ * const oneDayAgo = Date.now() - 24 * 60 * 60 * 1000
96
+ * const recent = await searchHistory({ startTime: oneDayAgo })
97
+ *
98
+ * // Combined search: text type, favorite items from a specific app
99
+ * const filtered = await searchHistory({
100
+ * type: 'text',
101
+ * isFavorite: true,
102
+ * sourceApp: 'com.apple.Safari'
103
+ * })
104
+ * ```
105
+ */
106
+ async searchHistory(options: ClipboardSearchOptions = {}): Promise<ClipboardSearchResponse> {
107
+ // Use the extended clipboard:get-history interface with search parameters
108
+ const response = await channel.send('clipboard:get-history', options)
109
+ const items = Array.isArray(response?.history)
110
+ ? response.history.map((item: PluginClipboardItem) => normalizeItem(item) ?? item)
111
+ : []
112
+ return {
113
+ items,
114
+ total: response?.total ?? 0,
115
+ page: response?.page ?? 1,
116
+ pageSize: response?.pageSize ?? 20,
117
+ }
118
+ },
119
+
82
120
  onDidChange(callback: (item: PluginClipboardItem) => void): () => void {
83
121
  return channel.regChannel('core-box:clipboard-change', ({ data }) => {
84
122
  const item = (data && 'item' in data ? data.item : data) as PluginClipboardItem
@@ -110,6 +110,41 @@ export interface PluginClipboardHistoryResponse {
110
110
  pageSize: number
111
111
  }
112
112
 
113
+ /**
114
+ * Clipboard search options for filtering and sorting clipboard history.
115
+ */
116
+ export interface PluginClipboardSearchOptions {
117
+ /** Keyword for fuzzy search in content */
118
+ keyword?: string
119
+ /** Start time for filtering (Unix timestamp in milliseconds) */
120
+ startTime?: number
121
+ /** End time for filtering (Unix timestamp in milliseconds) */
122
+ endTime?: number
123
+ /** Filter by clipboard item type */
124
+ type?: 'text' | 'image' | 'files'
125
+ /** Filter by favorite status */
126
+ isFavorite?: boolean
127
+ /** Filter by source application */
128
+ sourceApp?: string
129
+ /** Page number for pagination (default: 1) */
130
+ page?: number
131
+ /** Number of items per page (default: 20, max: 100) */
132
+ pageSize?: number
133
+ /** Sort order by timestamp (default: 'desc') */
134
+ sortOrder?: 'asc' | 'desc'
135
+ }
136
+
137
+ /**
138
+ * Clipboard search response structure.
139
+ */
140
+ export interface PluginClipboardSearchResponse {
141
+ items: PluginClipboardItem[]
142
+ total: number
143
+ page: number
144
+ pageSize: number
145
+ }
146
+
147
+
113
148
  export interface ActiveAppSnapshot {
114
149
  identifier: string | null
115
150
  displayName: string | null