@talex-touch/utils 1.0.36 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@talex-touch/utils",
3
- "version": "1.0.36",
3
+ "version": "1.0.38",
4
4
  "private": false,
5
5
  "description": "Tuff series utils",
6
6
  "author": "TalexDreamSoul",
@@ -4,6 +4,7 @@
4
4
  * Provides a unified API for plugins to control the CoreBox window behavior,
5
5
  * including visibility, size, input field control, and input value access.
6
6
  */
7
+ import type { ITouchClientChannel } from '@talex-touch/utils/channel'
7
8
  import { ensureRendererChannel } from './channel'
8
9
 
9
10
  /**
@@ -193,32 +194,23 @@ export interface BoxSDK {
193
194
  *
194
195
  * @internal
195
196
  */
196
- export function createBoxSDK(channel: any): BoxSDK {
197
- const send: (eventName: string, payload?: any) => Promise<any> =
198
- typeof channel?.sendToMain === 'function'
199
- ? channel.sendToMain.bind(channel)
200
- : typeof channel?.send === 'function'
201
- ? channel.send.bind(channel)
202
- : (() => {
203
- throw new Error('[Box SDK] Channel send function not available')
204
- })()
205
-
197
+ export function createBoxSDK(channel: ITouchClientChannel): BoxSDK {
206
198
  return {
207
199
  hide(): void {
208
- send('core-box:hide').catch((error: any) => {
200
+ channel.send('core-box:hide').catch((error: any) => {
209
201
  console.error('[Box SDK] Failed to hide CoreBox:', error)
210
202
  })
211
203
  },
212
204
 
213
205
  show(): void {
214
- send('core-box:show').catch((error: any) => {
206
+ channel.send('core-box:show').catch((error: any) => {
215
207
  console.error('[Box SDK] Failed to show CoreBox:', error)
216
208
  })
217
209
  },
218
210
 
219
211
  async expand(options?: BoxExpandOptions): Promise<void> {
220
212
  try {
221
- await send('core-box:expand', options || {})
213
+ await channel.send('core-box:expand', options || {})
222
214
  }
223
215
  catch (error) {
224
216
  console.error('[Box SDK] Failed to expand CoreBox:', error)
@@ -228,7 +220,7 @@ export function createBoxSDK(channel: any): BoxSDK {
228
220
 
229
221
  async shrink(): Promise<void> {
230
222
  try {
231
- await send('core-box:expand', { mode: 'collapse' })
223
+ await channel.send('core-box:expand', { mode: 'collapse' })
232
224
  }
233
225
  catch (error) {
234
226
  console.error('[Box SDK] Failed to shrink CoreBox:', error)
@@ -238,7 +230,7 @@ export function createBoxSDK(channel: any): BoxSDK {
238
230
 
239
231
  async hideInput(): Promise<void> {
240
232
  try {
241
- await send('core-box:hide-input')
233
+ await channel.send('core-box:hide-input')
242
234
  }
243
235
  catch (error) {
244
236
  console.error('[Box SDK] Failed to hide input:', error)
@@ -248,7 +240,7 @@ export function createBoxSDK(channel: any): BoxSDK {
248
240
 
249
241
  async showInput(): Promise<void> {
250
242
  try {
251
- await send('core-box:show-input')
243
+ await channel.send('core-box:show-input')
252
244
  }
253
245
  catch (error) {
254
246
  console.error('[Box SDK] Failed to show input:', error)
@@ -258,7 +250,7 @@ export function createBoxSDK(channel: any): BoxSDK {
258
250
 
259
251
  async getInput(): Promise<string> {
260
252
  try {
261
- const result = await send('core-box:get-input')
253
+ const result = await channel.send('core-box:get-input')
262
254
  return result?.data?.input || result?.input || ''
263
255
  }
264
256
  catch (error) {
@@ -269,7 +261,7 @@ export function createBoxSDK(channel: any): BoxSDK {
269
261
 
270
262
  async setInput(value: string): Promise<void> {
271
263
  try {
272
- await send('core-box:set-input', { value })
264
+ await channel.send('core-box:set-input', { value })
273
265
  }
274
266
  catch (error) {
275
267
  console.error('[Box SDK] Failed to set input:', error)
@@ -279,7 +271,7 @@ export function createBoxSDK(channel: any): BoxSDK {
279
271
 
280
272
  async clearInput(): Promise<void> {
281
273
  try {
282
- await send('core-box:clear-input')
274
+ await channel.send('core-box:clear-input')
283
275
  }
284
276
  catch (error) {
285
277
  console.error('[Box SDK] Failed to clear input:', error)
@@ -289,7 +281,7 @@ export function createBoxSDK(channel: any): BoxSDK {
289
281
 
290
282
  async allowInput(): Promise<void> {
291
283
  try {
292
- await send('core-box:allow-input')
284
+ await channel.send('core-box:allow-input')
293
285
  }
294
286
  catch (error) {
295
287
  console.error('[Box SDK] Failed to enable input monitoring:', error)
@@ -299,7 +291,7 @@ export function createBoxSDK(channel: any): BoxSDK {
299
291
 
300
292
  async allowClipboard(types: number): Promise<void> {
301
293
  try {
302
- await send('core-box:allow-clipboard', types)
294
+ await channel.send('core-box:allow-clipboard', types)
303
295
  }
304
296
  catch (error) {
305
297
  console.error('[Box SDK] Failed to enable clipboard monitoring:', error)
@@ -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 = 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
@@ -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