@talex-touch/utils 1.0.37 → 1.0.38
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 +1 -1
- package/plugin/sdk/clipboard.ts +44 -4
- package/plugin/sdk/types.ts +35 -0
package/package.json
CHANGED
package/plugin/sdk/clipboard.ts
CHANGED
|
@@ -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
|
|
27
|
-
page?: number
|
|
28
|
-
}
|
|
26
|
+
export type ClipboardHistoryOptions = Omit<PluginClipboardSearchOptions, 'keyword' | 'startTime' | 'endTime' | 'type' | 'isFavorite' | 'sourceApp' | 'sortOrder'> & { page?: number }
|
|
29
27
|
|
|
30
28
|
export interface ClipboardFavoriteOptions {
|
|
31
29
|
id: number
|
|
@@ -46,6 +44,10 @@ export interface ClipboardApplyOptions {
|
|
|
46
44
|
type?: PluginClipboardItem['type']
|
|
47
45
|
}
|
|
48
46
|
|
|
47
|
+
export type ClipboardSearchOptions = PluginClipboardSearchOptions
|
|
48
|
+
export type ClipboardSearchResponse = PluginClipboardSearchResponse
|
|
49
|
+
|
|
50
|
+
|
|
49
51
|
export function useClipboardHistory() {
|
|
50
52
|
const channel = ensurePluginChannel()
|
|
51
53
|
|
|
@@ -79,6 +81,44 @@ export function useClipboardHistory() {
|
|
|
79
81
|
await channel.send('clipboard:clear-history')
|
|
80
82
|
},
|
|
81
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Search clipboard history with advanced filtering options.
|
|
86
|
+
* Supports keyword search, time-based filtering, and combined filters.
|
|
87
|
+
*
|
|
88
|
+
* @param options - Search options
|
|
89
|
+
* @returns Search results with pagination metadata
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* // Search by keyword
|
|
94
|
+
* const result = await searchHistory({ keyword: 'hello' })
|
|
95
|
+
*
|
|
96
|
+
* // Search by time range (last 24 hours)
|
|
97
|
+
* const oneDayAgo = Date.now() - 24 * 60 * 60 * 1000
|
|
98
|
+
* const recent = await searchHistory({ startTime: oneDayAgo })
|
|
99
|
+
*
|
|
100
|
+
* // Combined search: text type, favorite items from a specific app
|
|
101
|
+
* const filtered = await searchHistory({
|
|
102
|
+
* type: 'text',
|
|
103
|
+
* isFavorite: true,
|
|
104
|
+
* sourceApp: 'com.apple.Safari'
|
|
105
|
+
* })
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
async searchHistory(options: ClipboardSearchOptions = {}): Promise<ClipboardSearchResponse> {
|
|
109
|
+
// Use the extended clipboard:get-history interface with search parameters
|
|
110
|
+
const response = await channel.send('clipboard:get-history', options)
|
|
111
|
+
const items = Array.isArray(response?.history)
|
|
112
|
+
? response.history.map((item: PluginClipboardItem) => normalizeItem(item) ?? item)
|
|
113
|
+
: []
|
|
114
|
+
return {
|
|
115
|
+
items,
|
|
116
|
+
total: response?.total ?? 0,
|
|
117
|
+
page: response?.page ?? 1,
|
|
118
|
+
pageSize: response?.pageSize ?? 20,
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
|
|
82
122
|
onDidChange(callback: (item: PluginClipboardItem) => void): () => void {
|
|
83
123
|
return channel.regChannel('core-box:clipboard-change', ({ data }) => {
|
|
84
124
|
const item = (data && 'item' in data ? data.item : data) as PluginClipboardItem
|
package/plugin/sdk/types.ts
CHANGED
|
@@ -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
|