kirby-types 0.7.3 → 1.1.0
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 +269 -26
- package/index.d.ts +24 -2
- package/package.json +38 -9
- package/src/api.d.ts +40 -0
- package/src/blocks.d.ts +254 -16
- package/src/kql.d.ts +127 -1
- package/src/layout.d.ts +96 -29
- package/src/panel/api.d.ts +1003 -0
- package/src/panel/base.d.ts +789 -0
- package/src/panel/features.d.ts +1543 -0
- package/src/panel/helpers.d.ts +1030 -0
- package/src/panel/index.d.ts +1008 -0
- package/src/panel/libraries.d.ts +456 -0
- package/src/panel/writer.d.ts +280 -0
- package/src/query.d.ts +219 -5
|
@@ -0,0 +1,1030 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper type definitions for Kirby Panel.
|
|
3
|
+
*
|
|
4
|
+
* Provides types for the `$helper` utilities available on the Vue prototype.
|
|
5
|
+
*
|
|
6
|
+
* @see https://github.com/getkirby/kirby/tree/main/panel/src/helpers
|
|
7
|
+
* @since 4.0.0
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
// -----------------------------------------------------------------------------
|
|
11
|
+
// Array Helpers
|
|
12
|
+
// -----------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Search options for array filtering.
|
|
16
|
+
*/
|
|
17
|
+
export interface PanelArraySearchOptions {
|
|
18
|
+
/** Minimum query length (default: 0) */
|
|
19
|
+
min?: number;
|
|
20
|
+
/** Field to search in (default: `'text'`) */
|
|
21
|
+
field?: string;
|
|
22
|
+
/** Maximum results to return */
|
|
23
|
+
limit?: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Array helper utilities.
|
|
28
|
+
*
|
|
29
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/helpers/array.js
|
|
30
|
+
*/
|
|
31
|
+
export interface PanelHelpersArray {
|
|
32
|
+
/**
|
|
33
|
+
* Creates an array from an object or returns input if already array.
|
|
34
|
+
*
|
|
35
|
+
* @param object - Object or array to convert
|
|
36
|
+
* @returns Array of values
|
|
37
|
+
*/
|
|
38
|
+
fromObject: <T>(object: T[] | Record<string, T>) => T[];
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Searches through an array by query string.
|
|
42
|
+
*
|
|
43
|
+
* @param array - Array to search
|
|
44
|
+
* @param query - Search query
|
|
45
|
+
* @param options - Search options
|
|
46
|
+
* @returns Filtered array
|
|
47
|
+
*/
|
|
48
|
+
search: <T extends Record<string, unknown>>(
|
|
49
|
+
array: T[],
|
|
50
|
+
query: string,
|
|
51
|
+
options?: PanelArraySearchOptions,
|
|
52
|
+
) => T[];
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Sorts array by field and direction.
|
|
56
|
+
*
|
|
57
|
+
* @param array - Array to sort
|
|
58
|
+
* @param sortBy - Sort specification (e.g., `'name asc'`, `'date desc'`)
|
|
59
|
+
* @returns Sorted array
|
|
60
|
+
*/
|
|
61
|
+
sortBy: <T extends Record<string, unknown>>(
|
|
62
|
+
array: T[],
|
|
63
|
+
sortBy: string,
|
|
64
|
+
) => T[];
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Splits array into subarrays using delimiter element.
|
|
68
|
+
*
|
|
69
|
+
* @param array - Array to split
|
|
70
|
+
* @param delimiter - Element to split on
|
|
71
|
+
* @returns Array of subarrays
|
|
72
|
+
*/
|
|
73
|
+
split: <T>(array: T[], delimiter: T) => T[][];
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Wraps non-array values in an array.
|
|
77
|
+
*
|
|
78
|
+
* @param array - Value to wrap
|
|
79
|
+
* @returns Original array or wrapped value
|
|
80
|
+
*/
|
|
81
|
+
wrap: <T>(array: T | T[]) => T[];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// -----------------------------------------------------------------------------
|
|
85
|
+
// String Helpers
|
|
86
|
+
// -----------------------------------------------------------------------------
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Slug conversion rules.
|
|
90
|
+
*/
|
|
91
|
+
export type PanelSlugRules = Record<string, string>[];
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* String helper utilities.
|
|
95
|
+
*
|
|
96
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/helpers/string.js
|
|
97
|
+
*/
|
|
98
|
+
export interface PanelHelpersString {
|
|
99
|
+
/**
|
|
100
|
+
* Converts camelCase to kebab-case.
|
|
101
|
+
*
|
|
102
|
+
* @param string - String to convert
|
|
103
|
+
* @returns Kebab-case string
|
|
104
|
+
*/
|
|
105
|
+
camelToKebab: (string: string) => string;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Escapes HTML special characters.
|
|
109
|
+
*
|
|
110
|
+
* @param string - String to escape
|
|
111
|
+
* @returns Escaped string
|
|
112
|
+
*/
|
|
113
|
+
escapeHTML: (string: string) => string;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Checks if string contains emoji characters.
|
|
117
|
+
*
|
|
118
|
+
* @param string - String to check
|
|
119
|
+
* @returns True if contains emoji
|
|
120
|
+
*/
|
|
121
|
+
hasEmoji: (string: string) => boolean;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Checks if string is empty or falsy.
|
|
125
|
+
*
|
|
126
|
+
* @param string - String to check
|
|
127
|
+
* @returns True if empty
|
|
128
|
+
*/
|
|
129
|
+
isEmpty: (string: string | null | undefined) => boolean;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Converts first letter to lowercase.
|
|
133
|
+
*
|
|
134
|
+
* @param string - String to convert
|
|
135
|
+
* @returns Converted string
|
|
136
|
+
*/
|
|
137
|
+
lcfirst: (string: string) => string;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Trims characters from the beginning (greedy).
|
|
141
|
+
*
|
|
142
|
+
* @param string - String to trim
|
|
143
|
+
* @param replace - Characters to remove
|
|
144
|
+
* @returns Trimmed string
|
|
145
|
+
*/
|
|
146
|
+
ltrim: (string: string, replace: string) => string;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Prefixes string with zeros until length is reached.
|
|
150
|
+
*
|
|
151
|
+
* @param value - Value to pad
|
|
152
|
+
* @param length - Target length (default: 2)
|
|
153
|
+
* @returns Padded string
|
|
154
|
+
*/
|
|
155
|
+
pad: (value: string | number, length?: number) => string;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Generates random alphanumeric string.
|
|
159
|
+
*
|
|
160
|
+
* @param length - String length
|
|
161
|
+
* @returns Random string
|
|
162
|
+
*/
|
|
163
|
+
random: (length: number) => string;
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Trims characters from the end (greedy).
|
|
167
|
+
*
|
|
168
|
+
* @param string - String to trim
|
|
169
|
+
* @param replace - Characters to remove
|
|
170
|
+
* @returns Trimmed string
|
|
171
|
+
*/
|
|
172
|
+
rtrim: (string: string, replace: string) => string;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Converts string to ASCII slug.
|
|
176
|
+
*
|
|
177
|
+
* @param string - String to convert
|
|
178
|
+
* @param rules - Language/ASCII conversion rules
|
|
179
|
+
* @param allowed - Allowed characters (default: `'a-z0-9'`)
|
|
180
|
+
* @param separator - Separator character (default: `'-'`)
|
|
181
|
+
* @returns Slug string
|
|
182
|
+
*/
|
|
183
|
+
slug: (
|
|
184
|
+
string: string,
|
|
185
|
+
rules?: PanelSlugRules,
|
|
186
|
+
allowed?: string,
|
|
187
|
+
separator?: string,
|
|
188
|
+
) => string;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Strips HTML tags from string.
|
|
192
|
+
*
|
|
193
|
+
* @param string - String to strip
|
|
194
|
+
* @returns Plain text string
|
|
195
|
+
*/
|
|
196
|
+
stripHTML: (string: string) => string;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Replaces template placeholders with values.
|
|
200
|
+
* Supports `{{name}}` and `{{nested.prop}}` syntax.
|
|
201
|
+
*
|
|
202
|
+
* @param string - Template string
|
|
203
|
+
* @param values - Replacement values
|
|
204
|
+
* @returns Interpolated string
|
|
205
|
+
*/
|
|
206
|
+
template: (string: string, values?: Record<string, unknown>) => string;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Converts first letter to uppercase.
|
|
210
|
+
*
|
|
211
|
+
* @param string - String to convert
|
|
212
|
+
* @returns Converted string
|
|
213
|
+
*/
|
|
214
|
+
ucfirst: (string: string) => string;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Converts first letter of each word to uppercase.
|
|
218
|
+
*
|
|
219
|
+
* @param string - String to convert
|
|
220
|
+
* @returns Converted string
|
|
221
|
+
*/
|
|
222
|
+
ucwords: (string: string) => string;
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Converts HTML entities back to characters.
|
|
226
|
+
*
|
|
227
|
+
* @param string - String to unescape
|
|
228
|
+
* @returns Unescaped string
|
|
229
|
+
*/
|
|
230
|
+
unescapeHTML: (string: string) => string;
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Generates a UUID v4 string.
|
|
234
|
+
*
|
|
235
|
+
* @returns UUID string
|
|
236
|
+
*/
|
|
237
|
+
uuid: () => string;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// -----------------------------------------------------------------------------
|
|
241
|
+
// Object Helpers
|
|
242
|
+
// -----------------------------------------------------------------------------
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Object helper utilities.
|
|
246
|
+
*
|
|
247
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/helpers/object.js
|
|
248
|
+
*/
|
|
249
|
+
export interface PanelHelpersObject {
|
|
250
|
+
/**
|
|
251
|
+
* Deep clones an object or array using structuredClone.
|
|
252
|
+
*
|
|
253
|
+
* @param value - Value to clone
|
|
254
|
+
* @returns Cloned value
|
|
255
|
+
*/
|
|
256
|
+
clone: <T>(value: T) => T;
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Filters object entries by predicate.
|
|
260
|
+
*
|
|
261
|
+
* @param object - Object to filter
|
|
262
|
+
* @param predicate - Filter function
|
|
263
|
+
* @returns Filtered object
|
|
264
|
+
*/
|
|
265
|
+
filter: <T extends Record<string, unknown>>(
|
|
266
|
+
object: T,
|
|
267
|
+
predicate: (value: T[keyof T], key: string) => boolean,
|
|
268
|
+
) => Partial<T>;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Checks if value is empty (null, undefined, '', empty object/array).
|
|
272
|
+
*
|
|
273
|
+
* @param value - Value to check
|
|
274
|
+
* @returns True if empty
|
|
275
|
+
*/
|
|
276
|
+
isEmpty: (value: unknown) => boolean;
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Checks if input is a plain object (not array, null, etc.).
|
|
280
|
+
*
|
|
281
|
+
* @param input - Value to check
|
|
282
|
+
* @returns True if plain object
|
|
283
|
+
*/
|
|
284
|
+
isObject: (input: unknown) => input is Record<string, unknown>;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Counts keys in an object.
|
|
288
|
+
*
|
|
289
|
+
* @param object - Object to count
|
|
290
|
+
* @returns Number of keys
|
|
291
|
+
*/
|
|
292
|
+
length: (object: Record<string, unknown>) => number;
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Recursively merges source into target.
|
|
296
|
+
*
|
|
297
|
+
* @param target - Target object
|
|
298
|
+
* @param source - Source object
|
|
299
|
+
* @returns Merged object
|
|
300
|
+
*/
|
|
301
|
+
merge: <T extends Record<string, unknown>>(
|
|
302
|
+
target: T,
|
|
303
|
+
source?: Partial<T>,
|
|
304
|
+
) => T;
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Compares objects by JSON stringification.
|
|
308
|
+
*
|
|
309
|
+
* @param a - First object
|
|
310
|
+
* @param b - Second object
|
|
311
|
+
* @returns True if identical
|
|
312
|
+
*/
|
|
313
|
+
same: (a: unknown, b: unknown) => boolean;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Converts all object keys to lowercase.
|
|
317
|
+
*
|
|
318
|
+
* @param obj - Object to convert
|
|
319
|
+
* @returns Object with lowercase keys
|
|
320
|
+
*/
|
|
321
|
+
toLowerKeys: <T>(obj: Record<string, T>) => Record<string, T>;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// -----------------------------------------------------------------------------
|
|
325
|
+
// URL Helpers
|
|
326
|
+
// -----------------------------------------------------------------------------
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* URL helper utilities.
|
|
330
|
+
*
|
|
331
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/helpers/url.js
|
|
332
|
+
*/
|
|
333
|
+
export interface PanelHelpersUrl {
|
|
334
|
+
/**
|
|
335
|
+
* Returns the base URL from the `<base>` element or window origin.
|
|
336
|
+
*
|
|
337
|
+
* @returns Base URL
|
|
338
|
+
*/
|
|
339
|
+
base: () => URL;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Builds URLSearchParams from object, merging with origin query.
|
|
343
|
+
*
|
|
344
|
+
* @param query - Query parameters
|
|
345
|
+
* @param origin - Existing URL or query string
|
|
346
|
+
* @returns URLSearchParams object
|
|
347
|
+
*/
|
|
348
|
+
buildQuery: (
|
|
349
|
+
query?: Record<string, string | number | boolean | null>,
|
|
350
|
+
origin?: string | URL,
|
|
351
|
+
) => URLSearchParams;
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Builds a full URL object with query parameters.
|
|
355
|
+
*
|
|
356
|
+
* @param url - URL path or object
|
|
357
|
+
* @param query - Query parameters
|
|
358
|
+
* @param origin - Base origin URL
|
|
359
|
+
* @returns Complete URL object
|
|
360
|
+
*/
|
|
361
|
+
buildUrl: (
|
|
362
|
+
url?: string | URL,
|
|
363
|
+
query?: Record<string, string | number | boolean | null>,
|
|
364
|
+
origin?: string | URL,
|
|
365
|
+
) => URL;
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Checks if URL string starts with http:// or https://.
|
|
369
|
+
*
|
|
370
|
+
* @param url - URL to check
|
|
371
|
+
* @returns True if absolute
|
|
372
|
+
*/
|
|
373
|
+
isAbsolute: (url: string) => boolean;
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Checks if URL is on the same origin as current page.
|
|
377
|
+
*
|
|
378
|
+
* @param url - URL to check
|
|
379
|
+
* @returns True if same origin
|
|
380
|
+
*/
|
|
381
|
+
isSameOrigin: (url: string | URL) => boolean;
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Validates URL format.
|
|
385
|
+
*
|
|
386
|
+
* @param url - URL to validate
|
|
387
|
+
* @param strict - Use Kirby's URL regex for validation
|
|
388
|
+
* @returns True if valid URL
|
|
389
|
+
*/
|
|
390
|
+
isUrl: (url: string | URL, strict?: boolean) => boolean;
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* Converts relative path to absolute URL.
|
|
394
|
+
*
|
|
395
|
+
* @param path - Path to convert
|
|
396
|
+
* @param origin - Base origin
|
|
397
|
+
* @returns Absolute URL string
|
|
398
|
+
*/
|
|
399
|
+
makeAbsolute: (path: string, origin?: string | URL) => string;
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Converts string to URL object.
|
|
403
|
+
*
|
|
404
|
+
* @param url - URL string or object
|
|
405
|
+
* @param origin - Base origin for relative URLs
|
|
406
|
+
* @returns URL object
|
|
407
|
+
*/
|
|
408
|
+
toObject: (url: string | URL, origin?: string | URL) => URL;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// -----------------------------------------------------------------------------
|
|
412
|
+
// Clipboard Helpers
|
|
413
|
+
// -----------------------------------------------------------------------------
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* Clipboard helper utilities.
|
|
417
|
+
*
|
|
418
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/helpers/clipboard.js
|
|
419
|
+
*/
|
|
420
|
+
export interface PanelHelpersClipboard {
|
|
421
|
+
/**
|
|
422
|
+
* Reads from clipboard event or string.
|
|
423
|
+
*
|
|
424
|
+
* @param event - ClipboardEvent or string
|
|
425
|
+
* @param plain - Read as plain text only
|
|
426
|
+
* @returns Clipboard content
|
|
427
|
+
*/
|
|
428
|
+
read: (event: ClipboardEvent | string, plain?: boolean) => string;
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Writes to clipboard. Objects are auto-JSONified.
|
|
432
|
+
*
|
|
433
|
+
* @param value - Value to write
|
|
434
|
+
* @param event - ClipboardEvent for event-based writing
|
|
435
|
+
*/
|
|
436
|
+
write: (value: unknown, event?: ClipboardEvent) => void;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// -----------------------------------------------------------------------------
|
|
440
|
+
// Embed Helpers
|
|
441
|
+
// -----------------------------------------------------------------------------
|
|
442
|
+
|
|
443
|
+
/**
|
|
444
|
+
* Embed helper utilities for video providers.
|
|
445
|
+
*
|
|
446
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/helpers/embed.js
|
|
447
|
+
*/
|
|
448
|
+
export interface PanelHelpersEmbed {
|
|
449
|
+
/**
|
|
450
|
+
* Converts YouTube URL to embed URL.
|
|
451
|
+
*
|
|
452
|
+
* @param url - YouTube video URL
|
|
453
|
+
* @param doNotTrack - Enable privacy-enhanced mode
|
|
454
|
+
* @returns Embed URL or null
|
|
455
|
+
*/
|
|
456
|
+
youtube: (url: string, doNotTrack?: boolean) => string | null;
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Converts Vimeo URL to embed URL.
|
|
460
|
+
*
|
|
461
|
+
* @param url - Vimeo video URL
|
|
462
|
+
* @param doNotTrack - Enable do-not-track mode
|
|
463
|
+
* @returns Embed URL or null
|
|
464
|
+
*/
|
|
465
|
+
vimeo: (url: string, doNotTrack?: boolean) => string | null;
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Auto-detects provider and converts to embed URL.
|
|
469
|
+
*
|
|
470
|
+
* @param url - Video URL
|
|
471
|
+
* @param doNotTrack - Privacy mode
|
|
472
|
+
* @returns Embed URL or null
|
|
473
|
+
*/
|
|
474
|
+
video: (url: string, doNotTrack?: boolean) => string | null;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// -----------------------------------------------------------------------------
|
|
478
|
+
// Field Helpers
|
|
479
|
+
// -----------------------------------------------------------------------------
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Field definition object.
|
|
483
|
+
*/
|
|
484
|
+
export interface PanelFieldDefinition {
|
|
485
|
+
/** Field type */
|
|
486
|
+
type?: string;
|
|
487
|
+
/** Default value */
|
|
488
|
+
default?: unknown;
|
|
489
|
+
/** Whether field is disabled */
|
|
490
|
+
disabled?: boolean;
|
|
491
|
+
/** Conditional visibility */
|
|
492
|
+
when?: Record<string, unknown>;
|
|
493
|
+
/** API endpoint */
|
|
494
|
+
endpoints?: { field?: string; section?: string };
|
|
495
|
+
/** Nested fields */
|
|
496
|
+
fields?: Record<string, PanelFieldDefinition>;
|
|
497
|
+
/** Additional properties */
|
|
498
|
+
[key: string]: unknown;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Field helper utilities.
|
|
503
|
+
*
|
|
504
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/helpers/field.js
|
|
505
|
+
*/
|
|
506
|
+
export interface PanelHelpersField {
|
|
507
|
+
/**
|
|
508
|
+
* Gets default value for a field definition.
|
|
509
|
+
*
|
|
510
|
+
* @param field - Field definition
|
|
511
|
+
* @returns Default value
|
|
512
|
+
*/
|
|
513
|
+
defaultValue: (field: PanelFieldDefinition) => unknown;
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Creates form values object from field definitions.
|
|
517
|
+
*
|
|
518
|
+
* @param fields - Field definitions
|
|
519
|
+
* @returns Form values object
|
|
520
|
+
*/
|
|
521
|
+
form: (
|
|
522
|
+
fields: Record<string, PanelFieldDefinition>,
|
|
523
|
+
) => Record<string, unknown>;
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Checks if field is visible based on 'when' conditions.
|
|
527
|
+
*
|
|
528
|
+
* @param field - Field definition
|
|
529
|
+
* @param values - Current form values
|
|
530
|
+
* @returns True if visible
|
|
531
|
+
*/
|
|
532
|
+
isVisible: (
|
|
533
|
+
field: PanelFieldDefinition,
|
|
534
|
+
values: Record<string, unknown>,
|
|
535
|
+
) => boolean;
|
|
536
|
+
|
|
537
|
+
/**
|
|
538
|
+
* Propagates parent field's API endpoints to nested subfield definitions.
|
|
539
|
+
*
|
|
540
|
+
* @param field - Parent field
|
|
541
|
+
* @param fields - Subfield definitions
|
|
542
|
+
* @returns Enhanced field definitions
|
|
543
|
+
*/
|
|
544
|
+
subfields: (
|
|
545
|
+
field: PanelFieldDefinition,
|
|
546
|
+
fields: Record<string, PanelFieldDefinition>,
|
|
547
|
+
) => Record<string, PanelFieldDefinition>;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// -----------------------------------------------------------------------------
|
|
551
|
+
// File Helpers
|
|
552
|
+
// -----------------------------------------------------------------------------
|
|
553
|
+
|
|
554
|
+
/**
|
|
555
|
+
* File helper utilities.
|
|
556
|
+
*
|
|
557
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/helpers/file.js
|
|
558
|
+
*/
|
|
559
|
+
export interface PanelHelpersFile {
|
|
560
|
+
/**
|
|
561
|
+
* Extracts file extension from filename.
|
|
562
|
+
*
|
|
563
|
+
* @param filename - Filename
|
|
564
|
+
* @returns Extension without dot
|
|
565
|
+
*/
|
|
566
|
+
extension: (filename: string) => string;
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Extracts filename without extension.
|
|
570
|
+
*
|
|
571
|
+
* @param filename - Filename
|
|
572
|
+
* @returns Name without extension
|
|
573
|
+
*/
|
|
574
|
+
name: (filename: string) => string;
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* Formats byte size as human-readable string.
|
|
578
|
+
*
|
|
579
|
+
* @param size - Size in bytes
|
|
580
|
+
* @returns Formatted size (e.g., `'1.2 MB'`)
|
|
581
|
+
*/
|
|
582
|
+
niceSize: (size: number) => string;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// -----------------------------------------------------------------------------
|
|
586
|
+
// Keyboard Helpers
|
|
587
|
+
// -----------------------------------------------------------------------------
|
|
588
|
+
|
|
589
|
+
/**
|
|
590
|
+
* Keyboard helper utilities.
|
|
591
|
+
*
|
|
592
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/helpers/keyboard.js
|
|
593
|
+
*/
|
|
594
|
+
export interface PanelHelpersKeyboard {
|
|
595
|
+
/**
|
|
596
|
+
* Returns the meta key name for the current OS.
|
|
597
|
+
*
|
|
598
|
+
* @returns 'cmd' on Mac, 'ctrl' on other OS
|
|
599
|
+
*/
|
|
600
|
+
metaKey: () => "cmd" | "ctrl";
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
// -----------------------------------------------------------------------------
|
|
604
|
+
// Link Helpers
|
|
605
|
+
// -----------------------------------------------------------------------------
|
|
606
|
+
|
|
607
|
+
/**
|
|
608
|
+
* Link type definition.
|
|
609
|
+
*/
|
|
610
|
+
export interface PanelLinkType {
|
|
611
|
+
/** Detection function */
|
|
612
|
+
detect: (value: string) => boolean;
|
|
613
|
+
/** Icon name */
|
|
614
|
+
icon: string;
|
|
615
|
+
/** Type identifier */
|
|
616
|
+
id: string;
|
|
617
|
+
/** Display label */
|
|
618
|
+
label: string;
|
|
619
|
+
/** Extracts link from value */
|
|
620
|
+
link: (value: string) => string;
|
|
621
|
+
/** Input placeholder */
|
|
622
|
+
placeholder?: string;
|
|
623
|
+
/** Input validation pattern */
|
|
624
|
+
pattern?: string;
|
|
625
|
+
/** Input type */
|
|
626
|
+
input?: string;
|
|
627
|
+
/** Converts input to stored value */
|
|
628
|
+
value: (value: string) => string;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* Detected link result.
|
|
633
|
+
*/
|
|
634
|
+
export interface PanelLinkDetection {
|
|
635
|
+
/** Detected type */
|
|
636
|
+
type: string;
|
|
637
|
+
/** Extracted link */
|
|
638
|
+
link: string;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Link preview data.
|
|
643
|
+
*/
|
|
644
|
+
export interface PanelLinkPreview {
|
|
645
|
+
/** Display label */
|
|
646
|
+
label: string;
|
|
647
|
+
/** Preview image */
|
|
648
|
+
image?: { url: string; [key: string]: unknown };
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Link helper utilities.
|
|
653
|
+
*
|
|
654
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/helpers/link.js
|
|
655
|
+
*/
|
|
656
|
+
export interface PanelHelpersLink {
|
|
657
|
+
/**
|
|
658
|
+
* Detects link type and extracts link value.
|
|
659
|
+
*
|
|
660
|
+
* @param value - Link value to detect
|
|
661
|
+
* @param types - Custom type definitions
|
|
662
|
+
* @returns Detection result
|
|
663
|
+
*/
|
|
664
|
+
detect: (
|
|
665
|
+
value: string,
|
|
666
|
+
types?: Record<string, PanelLinkType>,
|
|
667
|
+
) => PanelLinkDetection;
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Converts file permalink to file:// UUID.
|
|
671
|
+
*
|
|
672
|
+
* @param value - Permalink value
|
|
673
|
+
* @returns File UUID
|
|
674
|
+
*/
|
|
675
|
+
getFileUUID: (value: string) => string;
|
|
676
|
+
|
|
677
|
+
/**
|
|
678
|
+
* Converts page permalink to page:// UUID.
|
|
679
|
+
*
|
|
680
|
+
* @param value - Permalink value
|
|
681
|
+
* @returns Page UUID
|
|
682
|
+
*/
|
|
683
|
+
getPageUUID: (value: string) => string;
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Checks if value is a file UUID or permalink.
|
|
687
|
+
*
|
|
688
|
+
* @param value - Value to check
|
|
689
|
+
* @returns True if file reference
|
|
690
|
+
*/
|
|
691
|
+
isFileUUID: (value: string) => boolean;
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Checks if value is a page UUID or permalink.
|
|
695
|
+
*
|
|
696
|
+
* @param value - Value to check
|
|
697
|
+
* @returns True if page reference
|
|
698
|
+
*/
|
|
699
|
+
isPageUUID: (value: string) => boolean;
|
|
700
|
+
|
|
701
|
+
/**
|
|
702
|
+
* Fetches preview data for a link.
|
|
703
|
+
*
|
|
704
|
+
* @param link - Link detection result
|
|
705
|
+
* @param fields - Fields to fetch
|
|
706
|
+
* @returns Preview data or null
|
|
707
|
+
*/
|
|
708
|
+
preview: (
|
|
709
|
+
link: PanelLinkDetection,
|
|
710
|
+
fields?: string[],
|
|
711
|
+
) => Promise<PanelLinkPreview | null>;
|
|
712
|
+
|
|
713
|
+
/**
|
|
714
|
+
* Returns available link types.
|
|
715
|
+
*
|
|
716
|
+
* @param keys - Filter to specific types
|
|
717
|
+
* @returns Link type definitions
|
|
718
|
+
*/
|
|
719
|
+
types: (keys?: string[]) => Record<string, PanelLinkType>;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
// -----------------------------------------------------------------------------
|
|
723
|
+
// Page Helpers
|
|
724
|
+
// -----------------------------------------------------------------------------
|
|
725
|
+
|
|
726
|
+
/**
|
|
727
|
+
* Page status button props.
|
|
728
|
+
*/
|
|
729
|
+
export interface PanelPageStatusProps {
|
|
730
|
+
/** Status text */
|
|
731
|
+
text: string;
|
|
732
|
+
/** Status icon */
|
|
733
|
+
icon: string;
|
|
734
|
+
/** Status color */
|
|
735
|
+
theme?: string;
|
|
736
|
+
/** Whether disabled */
|
|
737
|
+
disabled?: boolean;
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
/**
|
|
741
|
+
* Page helper utilities.
|
|
742
|
+
*
|
|
743
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/helpers/page.js
|
|
744
|
+
*/
|
|
745
|
+
export interface PanelHelpersPage {
|
|
746
|
+
/**
|
|
747
|
+
* Returns props for page status button.
|
|
748
|
+
*
|
|
749
|
+
* @param status - Page status ('draft', 'unlisted', 'listed')
|
|
750
|
+
* @param disabled - Whether to disable
|
|
751
|
+
* @returns Button props
|
|
752
|
+
*/
|
|
753
|
+
status: (status: string, disabled?: boolean) => PanelPageStatusProps;
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
// -----------------------------------------------------------------------------
|
|
757
|
+
// Upload Helpers
|
|
758
|
+
// -----------------------------------------------------------------------------
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* Upload progress callback.
|
|
762
|
+
*/
|
|
763
|
+
export type PanelUploadProgressCallback = (
|
|
764
|
+
xhr: XMLHttpRequest,
|
|
765
|
+
file: File,
|
|
766
|
+
percent: number,
|
|
767
|
+
) => void;
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* Upload complete callback.
|
|
771
|
+
*/
|
|
772
|
+
export type PanelUploadCompleteCallback = (
|
|
773
|
+
xhr: XMLHttpRequest,
|
|
774
|
+
file: File,
|
|
775
|
+
response: unknown,
|
|
776
|
+
) => void;
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Upload parameters.
|
|
780
|
+
*
|
|
781
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/helpers/upload.js
|
|
782
|
+
*/
|
|
783
|
+
export interface PanelUploadParams {
|
|
784
|
+
/** Upload endpoint URL */
|
|
785
|
+
url: string;
|
|
786
|
+
/** HTTP method (default: `'POST'`) */
|
|
787
|
+
method?: string;
|
|
788
|
+
/** Form field name (default: `'file'`) */
|
|
789
|
+
field?: string;
|
|
790
|
+
/** Override filename */
|
|
791
|
+
filename?: string;
|
|
792
|
+
/** Request headers */
|
|
793
|
+
headers?: Record<string, string>;
|
|
794
|
+
/** Additional form attributes */
|
|
795
|
+
attributes?: Record<string, unknown>;
|
|
796
|
+
/** AbortSignal for cancellation */
|
|
797
|
+
abort?: AbortSignal;
|
|
798
|
+
/** Progress callback */
|
|
799
|
+
progress?: PanelUploadProgressCallback;
|
|
800
|
+
/** Complete callback */
|
|
801
|
+
complete?: PanelUploadCompleteCallback;
|
|
802
|
+
/** Success callback */
|
|
803
|
+
success?: PanelUploadCompleteCallback;
|
|
804
|
+
/** Error callback */
|
|
805
|
+
error?: PanelUploadCompleteCallback;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
// -----------------------------------------------------------------------------
|
|
809
|
+
// Debounce/Throttle Helpers
|
|
810
|
+
// -----------------------------------------------------------------------------
|
|
811
|
+
|
|
812
|
+
/**
|
|
813
|
+
* Debounce options.
|
|
814
|
+
*/
|
|
815
|
+
export interface PanelDebounceOptions {
|
|
816
|
+
/** Call on leading edge (default: false) */
|
|
817
|
+
leading?: boolean;
|
|
818
|
+
/** Call on trailing edge (default: true) */
|
|
819
|
+
trailing?: boolean;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
/**
|
|
823
|
+
* Throttle options.
|
|
824
|
+
*/
|
|
825
|
+
export interface PanelThrottleOptions {
|
|
826
|
+
/** Call on leading edge (default: true) */
|
|
827
|
+
leading?: boolean;
|
|
828
|
+
/** Call on trailing edge (default: false) */
|
|
829
|
+
trailing?: boolean;
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
/**
|
|
833
|
+
* Debounced/throttled function with cancel method.
|
|
834
|
+
*/
|
|
835
|
+
export interface PanelDebouncedFunction<
|
|
836
|
+
T extends (...args: unknown[]) => unknown,
|
|
837
|
+
> {
|
|
838
|
+
(...args: Parameters<T>): ReturnType<T> | undefined;
|
|
839
|
+
/** Cancels pending invocation */
|
|
840
|
+
cancel: () => void;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
// -----------------------------------------------------------------------------
|
|
844
|
+
// Sort Helper
|
|
845
|
+
// -----------------------------------------------------------------------------
|
|
846
|
+
|
|
847
|
+
/**
|
|
848
|
+
* Sort options.
|
|
849
|
+
*/
|
|
850
|
+
export interface PanelSortOptions {
|
|
851
|
+
/** Sort descending (default: false) */
|
|
852
|
+
desc?: boolean;
|
|
853
|
+
/** Case insensitive comparison (default: false) */
|
|
854
|
+
insensitive?: boolean;
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
/**
|
|
858
|
+
* Comparator function for sorting.
|
|
859
|
+
*/
|
|
860
|
+
export type PanelComparator = (a: string, b: string) => number;
|
|
861
|
+
|
|
862
|
+
// -----------------------------------------------------------------------------
|
|
863
|
+
// Main Helpers Interface
|
|
864
|
+
// -----------------------------------------------------------------------------
|
|
865
|
+
|
|
866
|
+
/**
|
|
867
|
+
* Panel helpers available on the Vue prototype as `$helper`.
|
|
868
|
+
*
|
|
869
|
+
* Provides utility functions for common operations.
|
|
870
|
+
*
|
|
871
|
+
* @example
|
|
872
|
+
* ```ts
|
|
873
|
+
* // In a Vue component
|
|
874
|
+
* this.$helper.string.slug('Hello World');
|
|
875
|
+
* this.$helper.clone(someObject);
|
|
876
|
+
* this.$helper.uuid();
|
|
877
|
+
* ```
|
|
878
|
+
*
|
|
879
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/helpers/index.js
|
|
880
|
+
*/
|
|
881
|
+
export interface PanelHelpers {
|
|
882
|
+
/** Array utilities */
|
|
883
|
+
array: PanelHelpersArray;
|
|
884
|
+
|
|
885
|
+
/** Clipboard utilities */
|
|
886
|
+
clipboard: PanelHelpersClipboard;
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* Deep clones a value.
|
|
890
|
+
* Shortcut for `object.clone()`.
|
|
891
|
+
*/
|
|
892
|
+
clone: <T>(value: T) => T;
|
|
893
|
+
|
|
894
|
+
/**
|
|
895
|
+
* Resolves CSS color to CSS variable.
|
|
896
|
+
*
|
|
897
|
+
* @param value - Color name or value
|
|
898
|
+
* @returns CSS variable or original value
|
|
899
|
+
*/
|
|
900
|
+
color: (value: string) => string;
|
|
901
|
+
|
|
902
|
+
/**
|
|
903
|
+
* Creates a debounced function.
|
|
904
|
+
*
|
|
905
|
+
* @param fn - Function to debounce
|
|
906
|
+
* @param delay - Delay in milliseconds
|
|
907
|
+
* @param options - Debounce options
|
|
908
|
+
* @returns Debounced function with cancel method
|
|
909
|
+
*/
|
|
910
|
+
debounce: <T extends (...args: unknown[]) => unknown>(
|
|
911
|
+
fn: T,
|
|
912
|
+
delay: number,
|
|
913
|
+
options?: PanelDebounceOptions,
|
|
914
|
+
) => PanelDebouncedFunction<T>;
|
|
915
|
+
|
|
916
|
+
/** Video embed utilities */
|
|
917
|
+
embed: PanelHelpersEmbed;
|
|
918
|
+
|
|
919
|
+
/** Field utilities */
|
|
920
|
+
field: PanelHelpersField;
|
|
921
|
+
|
|
922
|
+
/** File utilities */
|
|
923
|
+
file: PanelHelpersFile;
|
|
924
|
+
|
|
925
|
+
/**
|
|
926
|
+
* Sets focus to element or first focusable child.
|
|
927
|
+
*
|
|
928
|
+
* @param element - Selector or element
|
|
929
|
+
* @param field - Specific input name to focus
|
|
930
|
+
*/
|
|
931
|
+
focus: (element: string | HTMLElement, field?: string) => void;
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* Checks if component is registered globally.
|
|
935
|
+
*
|
|
936
|
+
* @param name - Component name
|
|
937
|
+
* @returns True if registered
|
|
938
|
+
*/
|
|
939
|
+
isComponent: (name: string) => boolean;
|
|
940
|
+
|
|
941
|
+
/**
|
|
942
|
+
* Checks if event is a file drag/drop event.
|
|
943
|
+
*
|
|
944
|
+
* @param event - Event to check
|
|
945
|
+
* @returns True if file upload event
|
|
946
|
+
*/
|
|
947
|
+
isUploadEvent: (event: Event) => boolean;
|
|
948
|
+
|
|
949
|
+
/** Keyboard utilities */
|
|
950
|
+
keyboard: PanelHelpersKeyboard;
|
|
951
|
+
|
|
952
|
+
/** Link utilities */
|
|
953
|
+
link: PanelHelpersLink;
|
|
954
|
+
|
|
955
|
+
/** Object utilities */
|
|
956
|
+
object: PanelHelpersObject;
|
|
957
|
+
|
|
958
|
+
/**
|
|
959
|
+
* Left-pads value with zeros.
|
|
960
|
+
* Shortcut for `string.pad()`.
|
|
961
|
+
*/
|
|
962
|
+
pad: (value: string | number, length?: number) => string;
|
|
963
|
+
|
|
964
|
+
/** Page utilities */
|
|
965
|
+
page: PanelHelpersPage;
|
|
966
|
+
|
|
967
|
+
/**
|
|
968
|
+
* Converts aspect ratio to percentage.
|
|
969
|
+
*
|
|
970
|
+
* @param fraction - Ratio string (e.g., `'3/2'`)
|
|
971
|
+
* @param fallback - Fallback value (default: `'100%'`)
|
|
972
|
+
* @param vertical - Calculate for vertical orientation
|
|
973
|
+
* @returns Percentage string
|
|
974
|
+
*/
|
|
975
|
+
ratio: (fraction?: string, fallback?: string, vertical?: boolean) => string;
|
|
976
|
+
|
|
977
|
+
/**
|
|
978
|
+
* Converts string to slug.
|
|
979
|
+
* Shortcut for `string.slug()`.
|
|
980
|
+
*/
|
|
981
|
+
slug: (
|
|
982
|
+
string: string,
|
|
983
|
+
rules?: PanelSlugRules,
|
|
984
|
+
allowed?: string,
|
|
985
|
+
separator?: string,
|
|
986
|
+
) => string;
|
|
987
|
+
|
|
988
|
+
/**
|
|
989
|
+
* Creates a sort comparator function.
|
|
990
|
+
*
|
|
991
|
+
* @param options - Sort options
|
|
992
|
+
* @returns Comparator function
|
|
993
|
+
*/
|
|
994
|
+
sort: (options?: PanelSortOptions) => PanelComparator;
|
|
995
|
+
|
|
996
|
+
/** String utilities */
|
|
997
|
+
string: PanelHelpersString;
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* Creates a throttled function.
|
|
1001
|
+
*
|
|
1002
|
+
* @param fn - Function to throttle
|
|
1003
|
+
* @param delay - Delay in milliseconds
|
|
1004
|
+
* @param options - Throttle options
|
|
1005
|
+
* @returns Throttled function with cancel method
|
|
1006
|
+
*/
|
|
1007
|
+
throttle: <T extends (...args: unknown[]) => unknown>(
|
|
1008
|
+
fn: T,
|
|
1009
|
+
delay: number,
|
|
1010
|
+
options?: PanelThrottleOptions,
|
|
1011
|
+
) => PanelDebouncedFunction<T>;
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* Uploads a file via XMLHttpRequest.
|
|
1015
|
+
*
|
|
1016
|
+
* @param file - File to upload
|
|
1017
|
+
* @param params - Upload parameters
|
|
1018
|
+
* @returns Promise resolving to response
|
|
1019
|
+
*/
|
|
1020
|
+
upload: (file: File, params: PanelUploadParams) => Promise<unknown>;
|
|
1021
|
+
|
|
1022
|
+
/** URL utilities */
|
|
1023
|
+
url: PanelHelpersUrl;
|
|
1024
|
+
|
|
1025
|
+
/**
|
|
1026
|
+
* Generates UUID v4 string.
|
|
1027
|
+
* Shortcut for `string.uuid()`.
|
|
1028
|
+
*/
|
|
1029
|
+
uuid: () => string;
|
|
1030
|
+
}
|