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,1543 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feature type definitions for Kirby Panel.
|
|
3
|
+
*
|
|
4
|
+
* This module provides typed interfaces for all Panel features,
|
|
5
|
+
* including state objects, features, and modals.
|
|
6
|
+
*
|
|
7
|
+
* @see https://github.com/getkirby/kirby/tree/main/panel/src/panel
|
|
8
|
+
* @since 4.0.0
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
NotificationContext,
|
|
13
|
+
NotificationTheme,
|
|
14
|
+
NotificationType,
|
|
15
|
+
PanelEventCallback,
|
|
16
|
+
PanelEventListenerMap,
|
|
17
|
+
PanelEventListeners,
|
|
18
|
+
PanelFeature,
|
|
19
|
+
PanelFeatureDefaults,
|
|
20
|
+
PanelHistory,
|
|
21
|
+
PanelModal,
|
|
22
|
+
PanelRequestOptions,
|
|
23
|
+
PanelState,
|
|
24
|
+
} from "./base";
|
|
25
|
+
|
|
26
|
+
// -----------------------------------------------------------------------------
|
|
27
|
+
// Timer
|
|
28
|
+
// -----------------------------------------------------------------------------
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Simple timer utility for auto-closing notifications.
|
|
32
|
+
*
|
|
33
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/timer.js
|
|
34
|
+
* @since 4.0.0
|
|
35
|
+
*/
|
|
36
|
+
export interface PanelTimer {
|
|
37
|
+
/** Current interval ID, or null if not running */
|
|
38
|
+
interval: ReturnType<typeof setInterval> | null;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Starts the timer with a callback.
|
|
42
|
+
* Stops any previous timer first.
|
|
43
|
+
*
|
|
44
|
+
* @param timeout - Delay in milliseconds
|
|
45
|
+
* @param callback - Function to call after timeout
|
|
46
|
+
*/
|
|
47
|
+
start: (timeout: number | null, callback: () => void) => void;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Stops the timer and clears the interval.
|
|
51
|
+
*/
|
|
52
|
+
stop: () => void;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// -----------------------------------------------------------------------------
|
|
56
|
+
// Activation
|
|
57
|
+
// -----------------------------------------------------------------------------
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Default state for the activation feature.
|
|
61
|
+
*/
|
|
62
|
+
export interface PanelActivationDefaults {
|
|
63
|
+
/** Whether the activation card is visible */
|
|
64
|
+
isOpen: boolean;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Activation state for license registration prompts.
|
|
69
|
+
*
|
|
70
|
+
* Controls visibility of the license activation card based on
|
|
71
|
+
* session storage state.
|
|
72
|
+
*
|
|
73
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/activiation.js
|
|
74
|
+
* @since 4.0.0
|
|
75
|
+
*/
|
|
76
|
+
export interface PanelActivation extends PanelState<PanelActivationDefaults> {
|
|
77
|
+
/** Whether the activation card is visible */
|
|
78
|
+
isOpen: boolean;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Closes the activation card and persists state to session storage.
|
|
82
|
+
*/
|
|
83
|
+
close: () => void;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Opens the activation card and clears session storage state.
|
|
87
|
+
*/
|
|
88
|
+
open: () => void;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// -----------------------------------------------------------------------------
|
|
92
|
+
// Drag
|
|
93
|
+
// -----------------------------------------------------------------------------
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Default state for drag operations.
|
|
97
|
+
*/
|
|
98
|
+
export interface PanelDragDefaults {
|
|
99
|
+
/** Type of item being dragged */
|
|
100
|
+
type: string | null;
|
|
101
|
+
/** Data associated with the dragged item */
|
|
102
|
+
data: Record<string, unknown>;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Drag state for tracking drag-and-drop operations.
|
|
107
|
+
*
|
|
108
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/drag.js
|
|
109
|
+
* @since 4.0.0
|
|
110
|
+
*/
|
|
111
|
+
export interface PanelDrag extends PanelState<PanelDragDefaults> {
|
|
112
|
+
/** Type of item being dragged */
|
|
113
|
+
type: string | null;
|
|
114
|
+
/** Data associated with the dragged item */
|
|
115
|
+
data: Record<string, unknown>;
|
|
116
|
+
|
|
117
|
+
/** Whether a drag operation is in progress */
|
|
118
|
+
readonly isDragging: boolean;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Starts a drag operation with type and data.
|
|
122
|
+
*
|
|
123
|
+
* @param type - Drag item type (e.g., `'page'`, `'file'`)
|
|
124
|
+
* @param data - Associated data
|
|
125
|
+
*/
|
|
126
|
+
start: (type: string, data: Record<string, unknown>) => void;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Stops the current drag operation and resets state.
|
|
130
|
+
*/
|
|
131
|
+
stop: () => void;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// -----------------------------------------------------------------------------
|
|
135
|
+
// Theme
|
|
136
|
+
// -----------------------------------------------------------------------------
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Default state for theme management.
|
|
140
|
+
*/
|
|
141
|
+
export interface PanelThemeDefaults {
|
|
142
|
+
/** User's theme preference from localStorage */
|
|
143
|
+
setting: string | null;
|
|
144
|
+
/** System preference from media query */
|
|
145
|
+
system: "light" | "dark";
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Theme type values.
|
|
150
|
+
*/
|
|
151
|
+
export type PanelThemeValue = "light" | "dark" | "system";
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Theme state for managing Panel color scheme.
|
|
155
|
+
*
|
|
156
|
+
* Supports user preference, system preference, and config-based themes.
|
|
157
|
+
* Watches system media query for dark mode changes.
|
|
158
|
+
*
|
|
159
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/theme.js
|
|
160
|
+
* @since 5.0.0
|
|
161
|
+
*/
|
|
162
|
+
export interface PanelTheme extends Omit<
|
|
163
|
+
PanelState<PanelThemeDefaults>,
|
|
164
|
+
"reset" | "set"
|
|
165
|
+
> {
|
|
166
|
+
/** User's theme preference from localStorage */
|
|
167
|
+
setting: string | null;
|
|
168
|
+
/** System preference from media query */
|
|
169
|
+
system: "light" | "dark";
|
|
170
|
+
|
|
171
|
+
/** Theme from Panel config */
|
|
172
|
+
readonly config: string;
|
|
173
|
+
|
|
174
|
+
/** Resolved current theme */
|
|
175
|
+
readonly current: "light" | "dark";
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Resets theme to config/system default.
|
|
179
|
+
* Removes localStorage preference.
|
|
180
|
+
*/
|
|
181
|
+
reset: () => void;
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Sets user theme preference.
|
|
185
|
+
* Persists to localStorage.
|
|
186
|
+
*
|
|
187
|
+
* @param theme - Theme value
|
|
188
|
+
*/
|
|
189
|
+
set: (theme: PanelThemeValue) => void;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// -----------------------------------------------------------------------------
|
|
193
|
+
// Language (Content Language)
|
|
194
|
+
// -----------------------------------------------------------------------------
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Default state for content language.
|
|
198
|
+
*/
|
|
199
|
+
export interface PanelLanguageDefaults {
|
|
200
|
+
/** Language code (e.g., `'en'`, `'de'`) */
|
|
201
|
+
code: string | null;
|
|
202
|
+
/** Whether this is the default language */
|
|
203
|
+
default: boolean;
|
|
204
|
+
/** Text direction */
|
|
205
|
+
direction: "ltr" | "rtl";
|
|
206
|
+
/** Language name */
|
|
207
|
+
name: string | null;
|
|
208
|
+
/** Slug conversion rules */
|
|
209
|
+
rules: Record<string, string> | null;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Content language state.
|
|
214
|
+
*
|
|
215
|
+
* Represents the current content language for multilingual sites.
|
|
216
|
+
*
|
|
217
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/language.js
|
|
218
|
+
* @since 4.0.0
|
|
219
|
+
*/
|
|
220
|
+
export interface PanelLanguage extends PanelState<PanelLanguageDefaults> {
|
|
221
|
+
/** Language code (e.g., `'en'`, `'de'`) */
|
|
222
|
+
code: string | null;
|
|
223
|
+
/** Whether this is the default language */
|
|
224
|
+
default: boolean;
|
|
225
|
+
/** Text direction */
|
|
226
|
+
direction: "ltr" | "rtl";
|
|
227
|
+
/** Language name */
|
|
228
|
+
name: string | null;
|
|
229
|
+
/** Slug conversion rules */
|
|
230
|
+
rules: Record<string, string> | null;
|
|
231
|
+
|
|
232
|
+
/** Alias for `default` property */
|
|
233
|
+
readonly isDefault: boolean;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// -----------------------------------------------------------------------------
|
|
237
|
+
// Menu
|
|
238
|
+
// -----------------------------------------------------------------------------
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Menu entry types.
|
|
242
|
+
*/
|
|
243
|
+
export interface PanelMenuEntry {
|
|
244
|
+
/** Whether this entry is currently active */
|
|
245
|
+
current: boolean;
|
|
246
|
+
/** Icon name */
|
|
247
|
+
icon: string;
|
|
248
|
+
/** Link URL */
|
|
249
|
+
link: string;
|
|
250
|
+
/** Display text */
|
|
251
|
+
text: string;
|
|
252
|
+
/** Tooltip text */
|
|
253
|
+
title: string;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Default state for the sidebar menu.
|
|
258
|
+
*/
|
|
259
|
+
export interface PanelMenuDefaults {
|
|
260
|
+
/** Menu entries (items or separator strings) */
|
|
261
|
+
entries: (PanelMenuEntry | "-")[];
|
|
262
|
+
/** Whether menu is being hovered */
|
|
263
|
+
hover: boolean;
|
|
264
|
+
/** Whether menu is expanded */
|
|
265
|
+
isOpen: boolean;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Sidebar menu state.
|
|
270
|
+
*
|
|
271
|
+
* Manages the Panel sidebar with responsive behavior
|
|
272
|
+
* for mobile and desktop layouts.
|
|
273
|
+
*
|
|
274
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/menu.js
|
|
275
|
+
* @since 4.0.0
|
|
276
|
+
*/
|
|
277
|
+
export interface PanelMenu extends Omit<PanelState<PanelMenuDefaults>, "set"> {
|
|
278
|
+
/** Menu entries (items or separator strings) */
|
|
279
|
+
entries: (PanelMenuEntry | "-")[];
|
|
280
|
+
/** Whether menu is being hovered */
|
|
281
|
+
hover: boolean;
|
|
282
|
+
/** Whether menu is expanded */
|
|
283
|
+
isOpen: boolean;
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Handles outside clicks to close mobile menu.
|
|
287
|
+
* @internal
|
|
288
|
+
*/
|
|
289
|
+
blur: (event: Event) => void;
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Collapses the sidebar menu.
|
|
293
|
+
* Persists state to localStorage on desktop.
|
|
294
|
+
*/
|
|
295
|
+
close: () => void;
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Handles escape key to close mobile menu.
|
|
299
|
+
* @internal
|
|
300
|
+
*/
|
|
301
|
+
escape: () => void;
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Expands the sidebar menu.
|
|
305
|
+
* Removes localStorage state on desktop.
|
|
306
|
+
*/
|
|
307
|
+
open: () => void;
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Handles resize between mobile and desktop.
|
|
311
|
+
* @internal
|
|
312
|
+
*/
|
|
313
|
+
resize: () => void;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* Sets menu entries and handles initial resize.
|
|
317
|
+
*/
|
|
318
|
+
set: (entries: (PanelMenuEntry | "-")[]) => PanelMenuDefaults;
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Toggles the sidebar menu state.
|
|
322
|
+
*/
|
|
323
|
+
toggle: () => void;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// -----------------------------------------------------------------------------
|
|
327
|
+
// Notification
|
|
328
|
+
// -----------------------------------------------------------------------------
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Default state for notifications.
|
|
332
|
+
*/
|
|
333
|
+
export interface PanelNotificationDefaults {
|
|
334
|
+
/** Context where notification appears */
|
|
335
|
+
context: NotificationContext | null;
|
|
336
|
+
/** Additional details (for error dialogs) */
|
|
337
|
+
details: Record<string, unknown> | null;
|
|
338
|
+
/** Icon name */
|
|
339
|
+
icon: string | null;
|
|
340
|
+
/** Whether notification is visible */
|
|
341
|
+
isOpen: boolean;
|
|
342
|
+
/** Notification message */
|
|
343
|
+
message: string | null;
|
|
344
|
+
/** Visual theme */
|
|
345
|
+
theme: NotificationTheme | null;
|
|
346
|
+
/** Auto-close timeout in ms */
|
|
347
|
+
timeout: number | null;
|
|
348
|
+
/** Notification type */
|
|
349
|
+
type: NotificationType | null;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* Options for opening a notification.
|
|
354
|
+
*/
|
|
355
|
+
export interface PanelNotificationOptions {
|
|
356
|
+
/** Context where notification appears */
|
|
357
|
+
context?: NotificationContext;
|
|
358
|
+
/** Additional details */
|
|
359
|
+
details?: Record<string, unknown>;
|
|
360
|
+
/** Icon name */
|
|
361
|
+
icon?: string;
|
|
362
|
+
/** Notification message */
|
|
363
|
+
message?: string;
|
|
364
|
+
/** Visual theme */
|
|
365
|
+
theme?: NotificationTheme;
|
|
366
|
+
/** Auto-close timeout in ms (default: 4000 for non-errors) */
|
|
367
|
+
timeout?: number;
|
|
368
|
+
/** Notification type */
|
|
369
|
+
type?: NotificationType;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Error object for notifications.
|
|
374
|
+
*/
|
|
375
|
+
export interface PanelErrorObject {
|
|
376
|
+
/** Error message */
|
|
377
|
+
message: string;
|
|
378
|
+
/** Additional error details */
|
|
379
|
+
details?: Record<string, unknown>;
|
|
380
|
+
/** Error key for special handling */
|
|
381
|
+
key?: string;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Notification state for user feedback.
|
|
386
|
+
*
|
|
387
|
+
* Displays contextual notifications in view, dialog, or drawer.
|
|
388
|
+
* Supports auto-close timers and different severity levels.
|
|
389
|
+
*
|
|
390
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/notification.js
|
|
391
|
+
* @since 4.0.0
|
|
392
|
+
*/
|
|
393
|
+
export interface PanelNotification extends PanelState<PanelNotificationDefaults> {
|
|
394
|
+
/** Context where notification appears */
|
|
395
|
+
context: NotificationContext | null;
|
|
396
|
+
/** Additional details (for error dialogs) */
|
|
397
|
+
details: Record<string, unknown> | null;
|
|
398
|
+
/** Icon name */
|
|
399
|
+
icon: string | null;
|
|
400
|
+
/** Whether notification is visible */
|
|
401
|
+
isOpen: boolean;
|
|
402
|
+
/** Notification message */
|
|
403
|
+
message: string | null;
|
|
404
|
+
/** Visual theme */
|
|
405
|
+
theme: NotificationTheme | null;
|
|
406
|
+
/** Auto-close timeout in ms */
|
|
407
|
+
timeout: number | null;
|
|
408
|
+
/** Notification type */
|
|
409
|
+
type: NotificationType | null;
|
|
410
|
+
|
|
411
|
+
/** Timer for auto-close functionality */
|
|
412
|
+
timer: PanelTimer;
|
|
413
|
+
|
|
414
|
+
/** Whether this is a fatal error notification */
|
|
415
|
+
readonly isFatal: boolean;
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Closes the notification and resets state.
|
|
419
|
+
*/
|
|
420
|
+
close: () => PanelNotificationDefaults;
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Logs a deprecation warning to console.
|
|
424
|
+
*
|
|
425
|
+
* @param message - Deprecation message
|
|
426
|
+
*/
|
|
427
|
+
deprecated: (message: string) => void;
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Creates an error notification.
|
|
431
|
+
* Opens error dialog in view context.
|
|
432
|
+
*
|
|
433
|
+
* @param error - Error object, string, or Error instance
|
|
434
|
+
*/
|
|
435
|
+
error: (
|
|
436
|
+
error: Error | string | PanelErrorObject,
|
|
437
|
+
) => PanelNotificationDefaults;
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Creates a fatal error notification.
|
|
441
|
+
* Displayed in an isolated iframe.
|
|
442
|
+
*
|
|
443
|
+
* @param error - Error object, string, or Error instance
|
|
444
|
+
*/
|
|
445
|
+
fatal: (error: Error | string) => PanelNotificationDefaults;
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Creates an info notification.
|
|
449
|
+
*
|
|
450
|
+
* @param info - Message string or options object
|
|
451
|
+
*/
|
|
452
|
+
info: (info?: string | PanelNotificationOptions) => PanelNotificationDefaults;
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Opens a notification with the given options.
|
|
456
|
+
*
|
|
457
|
+
* @param notification - Message string or options object
|
|
458
|
+
*/
|
|
459
|
+
open: (
|
|
460
|
+
notification: string | PanelNotificationOptions,
|
|
461
|
+
) => PanelNotificationDefaults;
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* Creates a success notification.
|
|
465
|
+
*
|
|
466
|
+
* @param success - Message string or options object
|
|
467
|
+
*/
|
|
468
|
+
success: (
|
|
469
|
+
success?: string | PanelNotificationOptions,
|
|
470
|
+
) => PanelNotificationDefaults;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
// -----------------------------------------------------------------------------
|
|
474
|
+
// System
|
|
475
|
+
// -----------------------------------------------------------------------------
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Default state for system information.
|
|
479
|
+
*/
|
|
480
|
+
export interface PanelSystemDefaults {
|
|
481
|
+
/** ASCII character replacements for slugs */
|
|
482
|
+
ascii: Record<string, string>;
|
|
483
|
+
/** CSRF token for API requests */
|
|
484
|
+
csrf: string | null;
|
|
485
|
+
/** Whether running on localhost */
|
|
486
|
+
isLocal: boolean | null;
|
|
487
|
+
/** Locale names by code */
|
|
488
|
+
locales: Record<string, string>;
|
|
489
|
+
/** Slug rules by language */
|
|
490
|
+
slugs: Record<string, string>;
|
|
491
|
+
/** Site title */
|
|
492
|
+
title: string | null;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* System state with server configuration.
|
|
497
|
+
*
|
|
498
|
+
* Contains static system information from the server.
|
|
499
|
+
*
|
|
500
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/system.js
|
|
501
|
+
* @since 4.0.0
|
|
502
|
+
*/
|
|
503
|
+
export interface PanelSystem extends PanelState<PanelSystemDefaults> {
|
|
504
|
+
/** ASCII character replacements for slugs */
|
|
505
|
+
ascii: Record<string, string>;
|
|
506
|
+
/** CSRF token for API requests */
|
|
507
|
+
csrf: string | null;
|
|
508
|
+
/** Whether running on localhost */
|
|
509
|
+
isLocal: boolean | null;
|
|
510
|
+
/** Locale names by code */
|
|
511
|
+
locales: Record<string, string>;
|
|
512
|
+
/** Slug rules by language */
|
|
513
|
+
slugs: Record<string, string>;
|
|
514
|
+
/** Site title */
|
|
515
|
+
title: string | null;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// -----------------------------------------------------------------------------
|
|
519
|
+
// Translation (Interface Language)
|
|
520
|
+
// -----------------------------------------------------------------------------
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* Default state for interface translation.
|
|
524
|
+
*/
|
|
525
|
+
export interface PanelTranslationDefaults {
|
|
526
|
+
/** Translation code (e.g., `'en'`, `'de'`) */
|
|
527
|
+
code: string | null;
|
|
528
|
+
/** Translation strings by key */
|
|
529
|
+
data: Record<string, string>;
|
|
530
|
+
/** Text direction */
|
|
531
|
+
direction: "ltr" | "rtl";
|
|
532
|
+
/** Translation name */
|
|
533
|
+
name: string | null;
|
|
534
|
+
/** First day of week (`0`=Sunday, `1`=Monday) */
|
|
535
|
+
weekday: number;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* Interface translation state.
|
|
540
|
+
*
|
|
541
|
+
* Manages UI translations for the current user.
|
|
542
|
+
* Updates document language and direction on change.
|
|
543
|
+
*
|
|
544
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/translation.js
|
|
545
|
+
* @since 4.0.0
|
|
546
|
+
*/
|
|
547
|
+
export interface PanelTranslation extends PanelState<PanelTranslationDefaults> {
|
|
548
|
+
/** Translation code (e.g., `'en'`, `'de'`) */
|
|
549
|
+
code: string | null;
|
|
550
|
+
/** Translation strings by key */
|
|
551
|
+
data: Record<string, string>;
|
|
552
|
+
/** Text direction */
|
|
553
|
+
direction: "ltr" | "rtl";
|
|
554
|
+
/** Translation name */
|
|
555
|
+
name: string | null;
|
|
556
|
+
/** First day of week (`0`=Sunday, `1`=Monday) */
|
|
557
|
+
weekday: number;
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Sets translation state and updates document language/direction.
|
|
561
|
+
*/
|
|
562
|
+
set: (state: Partial<PanelTranslationDefaults>) => PanelTranslationDefaults;
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Fetches a translation string with optional placeholder replacement.
|
|
566
|
+
*
|
|
567
|
+
* @param key - Translation key
|
|
568
|
+
* @param data - Placeholder values
|
|
569
|
+
* @param fallback - Fallback if key not found
|
|
570
|
+
* @returns Translated string or undefined
|
|
571
|
+
*/
|
|
572
|
+
translate: (
|
|
573
|
+
key: string,
|
|
574
|
+
data?: Record<string, unknown>,
|
|
575
|
+
fallback?: string | null,
|
|
576
|
+
) => string | undefined;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
// -----------------------------------------------------------------------------
|
|
580
|
+
// User
|
|
581
|
+
// -----------------------------------------------------------------------------
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* Default state for the current user.
|
|
585
|
+
*/
|
|
586
|
+
export interface PanelUserDefaults {
|
|
587
|
+
/** User email */
|
|
588
|
+
email: string | null;
|
|
589
|
+
/** User ID */
|
|
590
|
+
id: string | null;
|
|
591
|
+
/** User's interface language */
|
|
592
|
+
language: string | null;
|
|
593
|
+
/** User's role */
|
|
594
|
+
role: string | null;
|
|
595
|
+
/** Username */
|
|
596
|
+
username: string | null;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Current user state.
|
|
601
|
+
*
|
|
602
|
+
* Contains information about the logged-in user.
|
|
603
|
+
*
|
|
604
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/user.js
|
|
605
|
+
* @since 4.0.0
|
|
606
|
+
*/
|
|
607
|
+
export interface PanelUser extends PanelState<PanelUserDefaults> {
|
|
608
|
+
/** User email */
|
|
609
|
+
email: string | null;
|
|
610
|
+
/** User ID */
|
|
611
|
+
id: string | null;
|
|
612
|
+
/** User's interface language */
|
|
613
|
+
language: string | null;
|
|
614
|
+
/** User's role */
|
|
615
|
+
role: string | null;
|
|
616
|
+
/** Username */
|
|
617
|
+
username: string | null;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// -----------------------------------------------------------------------------
|
|
621
|
+
// View
|
|
622
|
+
// -----------------------------------------------------------------------------
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* Breadcrumb item for view navigation.
|
|
626
|
+
*/
|
|
627
|
+
export interface PanelBreadcrumbItem {
|
|
628
|
+
/** Display label */
|
|
629
|
+
label: string;
|
|
630
|
+
/** Navigation link */
|
|
631
|
+
link: string;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* Default state for the view feature.
|
|
636
|
+
*/
|
|
637
|
+
export interface PanelViewDefaults extends PanelFeatureDefaults {
|
|
638
|
+
/** Breadcrumb navigation items */
|
|
639
|
+
breadcrumb: PanelBreadcrumbItem[];
|
|
640
|
+
/** Label for current breadcrumb */
|
|
641
|
+
breadcrumbLabel: string | null;
|
|
642
|
+
/** View icon */
|
|
643
|
+
icon: string | null;
|
|
644
|
+
/** View ID */
|
|
645
|
+
id: string | null;
|
|
646
|
+
/** View link */
|
|
647
|
+
link: string | null;
|
|
648
|
+
/** Default search type */
|
|
649
|
+
search: string;
|
|
650
|
+
/** View title */
|
|
651
|
+
title: string | null;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* View feature for main Panel content.
|
|
656
|
+
*
|
|
657
|
+
* Manages the primary view state, document title,
|
|
658
|
+
* and browser history.
|
|
659
|
+
*
|
|
660
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/view.js
|
|
661
|
+
* @since 4.0.0
|
|
662
|
+
*/
|
|
663
|
+
export interface PanelView extends Omit<
|
|
664
|
+
PanelFeature<PanelViewDefaults>,
|
|
665
|
+
"set"
|
|
666
|
+
> {
|
|
667
|
+
/** Breadcrumb navigation items */
|
|
668
|
+
breadcrumb: PanelBreadcrumbItem[];
|
|
669
|
+
/** Label for current breadcrumb */
|
|
670
|
+
breadcrumbLabel: string | null;
|
|
671
|
+
/** View icon */
|
|
672
|
+
icon: string | null;
|
|
673
|
+
/** View ID */
|
|
674
|
+
id: string | null;
|
|
675
|
+
/** View link */
|
|
676
|
+
link: string | null;
|
|
677
|
+
/** Default search type */
|
|
678
|
+
search: string;
|
|
679
|
+
/** View title */
|
|
680
|
+
title: string | null;
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Loads a view, canceling any previous request.
|
|
684
|
+
*/
|
|
685
|
+
load: (
|
|
686
|
+
url: string | URL,
|
|
687
|
+
options?: PanelRequestOptions | PanelEventCallback,
|
|
688
|
+
) => Promise<PanelViewDefaults>;
|
|
689
|
+
|
|
690
|
+
/**
|
|
691
|
+
* Sets view state and updates document title and browser URL.
|
|
692
|
+
*/
|
|
693
|
+
set: (state: Partial<PanelViewDefaults>) => void;
|
|
694
|
+
|
|
695
|
+
/**
|
|
696
|
+
* Submits the view form.
|
|
697
|
+
* @throws Error - Not yet implemented
|
|
698
|
+
*/
|
|
699
|
+
submit: () => Promise<never>;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
// -----------------------------------------------------------------------------
|
|
703
|
+
// Dropdown
|
|
704
|
+
// -----------------------------------------------------------------------------
|
|
705
|
+
|
|
706
|
+
/**
|
|
707
|
+
* Dropdown option item.
|
|
708
|
+
*/
|
|
709
|
+
export interface PanelDropdownOption {
|
|
710
|
+
/** Option text */
|
|
711
|
+
text: string;
|
|
712
|
+
/** Icon name */
|
|
713
|
+
icon?: string;
|
|
714
|
+
/** Click handler or link */
|
|
715
|
+
click?: () => void | string;
|
|
716
|
+
/** Whether option is disabled */
|
|
717
|
+
disabled?: boolean;
|
|
718
|
+
/** Additional properties */
|
|
719
|
+
[key: string]: unknown;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Dropdown feature for context menus.
|
|
724
|
+
*
|
|
725
|
+
* Manages dropdown menus loaded from the server
|
|
726
|
+
* or created programmatically.
|
|
727
|
+
*
|
|
728
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/dropdown.js
|
|
729
|
+
* @since 4.0.0
|
|
730
|
+
*/
|
|
731
|
+
export interface PanelDropdown extends PanelFeature<PanelFeatureDefaults> {
|
|
732
|
+
/**
|
|
733
|
+
* Closes the dropdown and resets state.
|
|
734
|
+
*/
|
|
735
|
+
close: () => void;
|
|
736
|
+
|
|
737
|
+
/**
|
|
738
|
+
* Opens a dropdown by URL or state object.
|
|
739
|
+
* URLs are prefixed with `/dropdowns/`.
|
|
740
|
+
*/
|
|
741
|
+
open: (
|
|
742
|
+
dropdown: string | URL | Partial<PanelFeatureDefaults>,
|
|
743
|
+
options?: PanelRequestOptions | PanelEventCallback,
|
|
744
|
+
) => Promise<PanelFeatureDefaults>;
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* Opens a dropdown asynchronously.
|
|
748
|
+
* @deprecated Use `open()` instead (since 4.0.0)
|
|
749
|
+
*/
|
|
750
|
+
openAsync: (
|
|
751
|
+
dropdown: string | URL | Partial<PanelFeatureDefaults>,
|
|
752
|
+
options?: PanelRequestOptions | PanelEventCallback,
|
|
753
|
+
) => () => Promise<PanelFeatureDefaults>;
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* Returns dropdown options array from props.
|
|
757
|
+
*/
|
|
758
|
+
options: () => PanelDropdownOption[];
|
|
759
|
+
|
|
760
|
+
/**
|
|
761
|
+
* Sets dropdown state, handling deprecated responses.
|
|
762
|
+
*/
|
|
763
|
+
set: (state: Partial<PanelFeatureDefaults>) => PanelFeatureDefaults;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// -----------------------------------------------------------------------------
|
|
767
|
+
// Dialog
|
|
768
|
+
// -----------------------------------------------------------------------------
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* Default state for the dialog modal.
|
|
772
|
+
*/
|
|
773
|
+
export interface PanelDialogDefaults extends PanelFeatureDefaults {
|
|
774
|
+
/** Unique dialog ID */
|
|
775
|
+
id: string | null;
|
|
776
|
+
/** Whether using legacy Vue component */
|
|
777
|
+
legacy: boolean;
|
|
778
|
+
/** Reference to legacy component */
|
|
779
|
+
ref: unknown;
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* Dialog modal for overlays.
|
|
784
|
+
*
|
|
785
|
+
* Supports both modern fiber dialogs and legacy Vue component dialogs.
|
|
786
|
+
*
|
|
787
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/dialog.js
|
|
788
|
+
* @since 4.0.0
|
|
789
|
+
*/
|
|
790
|
+
export interface PanelDialog extends PanelModal<PanelDialogDefaults> {
|
|
791
|
+
/** Whether using legacy Vue component */
|
|
792
|
+
legacy: boolean;
|
|
793
|
+
/** Reference to legacy component */
|
|
794
|
+
ref: unknown;
|
|
795
|
+
|
|
796
|
+
/**
|
|
797
|
+
* Closes the dialog, handling legacy components.
|
|
798
|
+
*/
|
|
799
|
+
close: () => Promise<void>;
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* Opens a dialog by URL, state object, or legacy component.
|
|
803
|
+
*/
|
|
804
|
+
open: (
|
|
805
|
+
dialog:
|
|
806
|
+
| string
|
|
807
|
+
| URL
|
|
808
|
+
| Partial<PanelDialogDefaults>
|
|
809
|
+
| { component: string; props?: Record<string, unknown> },
|
|
810
|
+
options?: PanelRequestOptions | PanelEventCallback,
|
|
811
|
+
) => Promise<PanelDialogDefaults>;
|
|
812
|
+
|
|
813
|
+
/**
|
|
814
|
+
* Opens a legacy Vue component dialog.
|
|
815
|
+
* @deprecated Since 4.0.0
|
|
816
|
+
*/
|
|
817
|
+
openComponent: (dialog: {
|
|
818
|
+
component: string;
|
|
819
|
+
props?: Record<string, unknown>;
|
|
820
|
+
on?: PanelEventListenerMap;
|
|
821
|
+
}) => Promise<void>;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
// -----------------------------------------------------------------------------
|
|
825
|
+
// Drawer
|
|
826
|
+
// -----------------------------------------------------------------------------
|
|
827
|
+
|
|
828
|
+
/**
|
|
829
|
+
* Default state for the drawer modal.
|
|
830
|
+
*/
|
|
831
|
+
export interface PanelDrawerDefaults extends PanelFeatureDefaults {
|
|
832
|
+
/** Unique drawer ID */
|
|
833
|
+
id: string | null;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
/**
|
|
837
|
+
* Drawer modal for side panels.
|
|
838
|
+
*
|
|
839
|
+
* Supports nested drawers with breadcrumb navigation.
|
|
840
|
+
*
|
|
841
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/drawer.js
|
|
842
|
+
* @since 4.0.0
|
|
843
|
+
*/
|
|
844
|
+
export interface PanelDrawer extends PanelModal<PanelDrawerDefaults> {
|
|
845
|
+
/** Breadcrumb from history milestones */
|
|
846
|
+
readonly breadcrumb: PanelHistory["milestones"];
|
|
847
|
+
|
|
848
|
+
/** Drawer icon, defaults to 'box' */
|
|
849
|
+
readonly icon: string;
|
|
850
|
+
|
|
851
|
+
/**
|
|
852
|
+
* Opens a drawer by URL or state object.
|
|
853
|
+
*/
|
|
854
|
+
open: (
|
|
855
|
+
drawer: string | URL | Partial<PanelDrawerDefaults>,
|
|
856
|
+
options?: PanelRequestOptions | PanelEventCallback,
|
|
857
|
+
) => Promise<PanelDrawerDefaults>;
|
|
858
|
+
|
|
859
|
+
/**
|
|
860
|
+
* Switches drawer tabs.
|
|
861
|
+
*
|
|
862
|
+
* @param tab - Tab name to switch to
|
|
863
|
+
*/
|
|
864
|
+
tab: (tab: string) => void;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
// -----------------------------------------------------------------------------
|
|
868
|
+
// Content
|
|
869
|
+
// -----------------------------------------------------------------------------
|
|
870
|
+
|
|
871
|
+
/**
|
|
872
|
+
* Content version representing saved or changed state.
|
|
873
|
+
*/
|
|
874
|
+
export interface PanelContentVersion {
|
|
875
|
+
[field: string]: unknown;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
/**
|
|
879
|
+
* Content versions container.
|
|
880
|
+
*/
|
|
881
|
+
export interface PanelContentVersions {
|
|
882
|
+
/** Original saved content */
|
|
883
|
+
latest: PanelContentVersion;
|
|
884
|
+
/** Current unsaved changes */
|
|
885
|
+
changes: PanelContentVersion;
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
/**
|
|
889
|
+
* Lock state for content editing.
|
|
890
|
+
*/
|
|
891
|
+
export interface PanelContentLock {
|
|
892
|
+
/** Whether content is locked by another user */
|
|
893
|
+
isLocked: boolean;
|
|
894
|
+
/** Lock modification timestamp */
|
|
895
|
+
modified?: Date;
|
|
896
|
+
/** User who holds the lock */
|
|
897
|
+
user?: { id: string; email: string };
|
|
898
|
+
/** Whether using legacy lock system */
|
|
899
|
+
isLegacy?: boolean;
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
/**
|
|
903
|
+
* Environment context for content operations.
|
|
904
|
+
*/
|
|
905
|
+
export interface PanelContentEnv {
|
|
906
|
+
/** API endpoint path */
|
|
907
|
+
api?: string;
|
|
908
|
+
/** Content language code */
|
|
909
|
+
language?: string;
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* Content feature for form state management.
|
|
914
|
+
*
|
|
915
|
+
* Manages content versions, saving, publishing, and lock handling.
|
|
916
|
+
* Provides automatic save on input with throttling.
|
|
917
|
+
*
|
|
918
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/content.js
|
|
919
|
+
* @since 5.0.0
|
|
920
|
+
*/
|
|
921
|
+
export interface PanelContent {
|
|
922
|
+
/** Reference to lock dialog if open */
|
|
923
|
+
dialog: PanelDialog | null;
|
|
924
|
+
|
|
925
|
+
/** Whether content is being saved/published/discarded */
|
|
926
|
+
isProcessing: boolean;
|
|
927
|
+
|
|
928
|
+
/** AbortController for save requests */
|
|
929
|
+
saveAbortController: AbortController | null;
|
|
930
|
+
|
|
931
|
+
/** Throttled save function (1000ms) */
|
|
932
|
+
saveLazy: ((
|
|
933
|
+
values?: Record<string, unknown>,
|
|
934
|
+
env?: PanelContentEnv,
|
|
935
|
+
) => Promise<void>) & { cancel: () => void };
|
|
936
|
+
|
|
937
|
+
/**
|
|
938
|
+
* Cancels any ongoing or scheduled save requests.
|
|
939
|
+
*/
|
|
940
|
+
cancelSaving: () => void;
|
|
941
|
+
|
|
942
|
+
/**
|
|
943
|
+
* Returns object with all changed fields.
|
|
944
|
+
*
|
|
945
|
+
* @param env - Environment context
|
|
946
|
+
* @throws Error if called for another view
|
|
947
|
+
*/
|
|
948
|
+
diff: (env?: PanelContentEnv) => Record<string, unknown>;
|
|
949
|
+
|
|
950
|
+
/**
|
|
951
|
+
* Discards all unpublished changes.
|
|
952
|
+
*
|
|
953
|
+
* @param env - Environment context
|
|
954
|
+
* @throws Error if locked or another view
|
|
955
|
+
*/
|
|
956
|
+
discard: (env?: PanelContentEnv) => Promise<void>;
|
|
957
|
+
|
|
958
|
+
/**
|
|
959
|
+
* Emits a content event with environment context.
|
|
960
|
+
*
|
|
961
|
+
* @param event - Event name (prefixed with 'content.')
|
|
962
|
+
* @param options - Additional event data
|
|
963
|
+
* @param env - Environment context
|
|
964
|
+
*/
|
|
965
|
+
emit: (
|
|
966
|
+
event: string,
|
|
967
|
+
options?: Record<string, unknown>,
|
|
968
|
+
env?: PanelContentEnv,
|
|
969
|
+
) => void;
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* Returns consistent environment with api and language.
|
|
973
|
+
*
|
|
974
|
+
* @param env - Override values
|
|
975
|
+
*/
|
|
976
|
+
env: (env?: PanelContentEnv) => Required<PanelContentEnv>;
|
|
977
|
+
|
|
978
|
+
/**
|
|
979
|
+
* Whether there are any unsaved changes.
|
|
980
|
+
*
|
|
981
|
+
* @param env - Environment context
|
|
982
|
+
*/
|
|
983
|
+
hasDiff: (env?: PanelContentEnv) => boolean;
|
|
984
|
+
|
|
985
|
+
/**
|
|
986
|
+
* Whether the API endpoint belongs to the current view.
|
|
987
|
+
*
|
|
988
|
+
* @param env - Environment context
|
|
989
|
+
*/
|
|
990
|
+
isCurrent: (env?: PanelContentEnv) => boolean;
|
|
991
|
+
|
|
992
|
+
/**
|
|
993
|
+
* Whether the current view is locked.
|
|
994
|
+
*
|
|
995
|
+
* @param env - Environment context
|
|
996
|
+
*/
|
|
997
|
+
isLocked: (env?: PanelContentEnv) => boolean;
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* Gets the lock state for the current view.
|
|
1001
|
+
*
|
|
1002
|
+
* @param env - Environment context
|
|
1003
|
+
* @throws Error if called for another view
|
|
1004
|
+
*/
|
|
1005
|
+
lock: (env?: PanelContentEnv) => PanelContentLock;
|
|
1006
|
+
|
|
1007
|
+
/**
|
|
1008
|
+
* Opens the lock dialog to inform about other edits.
|
|
1009
|
+
*
|
|
1010
|
+
* @param lock - Lock information
|
|
1011
|
+
*/
|
|
1012
|
+
lockDialog: (lock: PanelContentLock) => void;
|
|
1013
|
+
|
|
1014
|
+
/**
|
|
1015
|
+
* Merges new values with current changes.
|
|
1016
|
+
*
|
|
1017
|
+
* @param values - Values to merge
|
|
1018
|
+
* @param env - Environment context
|
|
1019
|
+
* @throws Error if called for another view
|
|
1020
|
+
*/
|
|
1021
|
+
merge: (
|
|
1022
|
+
values?: Record<string, unknown>,
|
|
1023
|
+
env?: PanelContentEnv,
|
|
1024
|
+
) => Record<string, unknown>;
|
|
1025
|
+
|
|
1026
|
+
/**
|
|
1027
|
+
* Publishes current changes.
|
|
1028
|
+
*
|
|
1029
|
+
* @param values - Additional values to merge first
|
|
1030
|
+
* @param env - Environment context
|
|
1031
|
+
* @throws Error if called for another view
|
|
1032
|
+
*/
|
|
1033
|
+
publish: (
|
|
1034
|
+
values?: Record<string, unknown>,
|
|
1035
|
+
env?: PanelContentEnv,
|
|
1036
|
+
) => Promise<void>;
|
|
1037
|
+
|
|
1038
|
+
/**
|
|
1039
|
+
* Sends a content API request.
|
|
1040
|
+
*
|
|
1041
|
+
* @param method - API method (save, publish, discard)
|
|
1042
|
+
* @param values - Request payload
|
|
1043
|
+
* @param env - Environment context
|
|
1044
|
+
*/
|
|
1045
|
+
request: (
|
|
1046
|
+
method?: "save" | "publish" | "discard",
|
|
1047
|
+
values?: Record<string, unknown>,
|
|
1048
|
+
env?: PanelContentEnv,
|
|
1049
|
+
) => Promise<unknown>;
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
* Saves current changes.
|
|
1053
|
+
*
|
|
1054
|
+
* @param values - Values to save
|
|
1055
|
+
* @param env - Environment context
|
|
1056
|
+
*/
|
|
1057
|
+
save: (
|
|
1058
|
+
values?: Record<string, unknown>,
|
|
1059
|
+
env?: PanelContentEnv,
|
|
1060
|
+
) => Promise<void>;
|
|
1061
|
+
|
|
1062
|
+
/**
|
|
1063
|
+
* Updates form values and saves.
|
|
1064
|
+
*
|
|
1065
|
+
* @param values - Values to update
|
|
1066
|
+
* @param env - Environment context
|
|
1067
|
+
*/
|
|
1068
|
+
update: (
|
|
1069
|
+
values?: Record<string, unknown>,
|
|
1070
|
+
env?: PanelContentEnv,
|
|
1071
|
+
) => Promise<void>;
|
|
1072
|
+
|
|
1073
|
+
/**
|
|
1074
|
+
* Updates form values with delay (throttled).
|
|
1075
|
+
*
|
|
1076
|
+
* @param values - Values to update
|
|
1077
|
+
* @param env - Environment context
|
|
1078
|
+
*/
|
|
1079
|
+
updateLazy: (values?: Record<string, unknown>, env?: PanelContentEnv) => void;
|
|
1080
|
+
|
|
1081
|
+
/**
|
|
1082
|
+
* Returns a specific version of content.
|
|
1083
|
+
*
|
|
1084
|
+
* @param versionId - Version identifier
|
|
1085
|
+
*/
|
|
1086
|
+
version: (versionId: "latest" | "changes") => PanelContentVersion;
|
|
1087
|
+
|
|
1088
|
+
/**
|
|
1089
|
+
* Returns all content versions.
|
|
1090
|
+
*/
|
|
1091
|
+
versions: () => PanelContentVersions;
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
// -----------------------------------------------------------------------------
|
|
1095
|
+
// Searcher
|
|
1096
|
+
// -----------------------------------------------------------------------------
|
|
1097
|
+
|
|
1098
|
+
/**
|
|
1099
|
+
* Search pagination info.
|
|
1100
|
+
*/
|
|
1101
|
+
export interface PanelSearchPagination {
|
|
1102
|
+
page?: number;
|
|
1103
|
+
limit?: number;
|
|
1104
|
+
total?: number;
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
/**
|
|
1108
|
+
* Search query options.
|
|
1109
|
+
*/
|
|
1110
|
+
export interface PanelSearchOptions {
|
|
1111
|
+
/** Page number */
|
|
1112
|
+
page?: number;
|
|
1113
|
+
/** Results per page */
|
|
1114
|
+
limit?: number;
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
/**
|
|
1118
|
+
* Search result from API.
|
|
1119
|
+
*/
|
|
1120
|
+
export interface PanelSearchResult {
|
|
1121
|
+
/** Result list (null if query too short) */
|
|
1122
|
+
results: unknown[] | null;
|
|
1123
|
+
/** Pagination info */
|
|
1124
|
+
pagination: PanelSearchPagination;
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
/**
|
|
1128
|
+
* Searcher feature for Panel search.
|
|
1129
|
+
*
|
|
1130
|
+
* Manages search dialog and query requests.
|
|
1131
|
+
*
|
|
1132
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/search.js
|
|
1133
|
+
* @since 4.4.0
|
|
1134
|
+
*/
|
|
1135
|
+
export interface PanelSearcher {
|
|
1136
|
+
/** AbortController for current request */
|
|
1137
|
+
controller: AbortController | null;
|
|
1138
|
+
|
|
1139
|
+
/** Number of active requests */
|
|
1140
|
+
requests: number;
|
|
1141
|
+
|
|
1142
|
+
/** Whether any search is loading */
|
|
1143
|
+
readonly isLoading: boolean;
|
|
1144
|
+
|
|
1145
|
+
/**
|
|
1146
|
+
* Opens the search dialog.
|
|
1147
|
+
*
|
|
1148
|
+
* @param type - Search type (e.g., `'pages'`, `'files'`, `'users'`)
|
|
1149
|
+
*/
|
|
1150
|
+
open: (type?: string) => void;
|
|
1151
|
+
|
|
1152
|
+
/**
|
|
1153
|
+
* Queries the search API.
|
|
1154
|
+
* Returns empty results for queries under 2 characters.
|
|
1155
|
+
*
|
|
1156
|
+
* @param type - Search type
|
|
1157
|
+
* @param query - Search query
|
|
1158
|
+
* @param options - Pagination options
|
|
1159
|
+
*/
|
|
1160
|
+
query: (
|
|
1161
|
+
type: string,
|
|
1162
|
+
query: string,
|
|
1163
|
+
options?: PanelSearchOptions,
|
|
1164
|
+
) => Promise<PanelSearchResult>;
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
// -----------------------------------------------------------------------------
|
|
1168
|
+
// Upload
|
|
1169
|
+
// -----------------------------------------------------------------------------
|
|
1170
|
+
|
|
1171
|
+
/**
|
|
1172
|
+
* Upload file state representing a file in the upload queue.
|
|
1173
|
+
*
|
|
1174
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/upload.js
|
|
1175
|
+
*/
|
|
1176
|
+
export interface PanelUploadFile {
|
|
1177
|
+
/** Unique file ID */
|
|
1178
|
+
id: string;
|
|
1179
|
+
/** Original File object */
|
|
1180
|
+
src: File;
|
|
1181
|
+
/** File name without extension */
|
|
1182
|
+
name: string;
|
|
1183
|
+
/** File extension without dot */
|
|
1184
|
+
extension: string;
|
|
1185
|
+
/** Original filename with extension */
|
|
1186
|
+
filename: string;
|
|
1187
|
+
/** File size in bytes */
|
|
1188
|
+
size: number;
|
|
1189
|
+
/** Formatted file size (e.g., `'1.2 MB'`) */
|
|
1190
|
+
niceSize: string;
|
|
1191
|
+
/** MIME type */
|
|
1192
|
+
type: string;
|
|
1193
|
+
/** Blob URL for preview */
|
|
1194
|
+
url: string;
|
|
1195
|
+
/** Upload progress (`0`-`100`) */
|
|
1196
|
+
progress: number;
|
|
1197
|
+
/** Whether upload completed */
|
|
1198
|
+
completed: boolean;
|
|
1199
|
+
/** Error message if failed */
|
|
1200
|
+
error: string | null;
|
|
1201
|
+
/** Response model after successful upload */
|
|
1202
|
+
model: unknown | null;
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
/**
|
|
1206
|
+
* Default state for upload feature.
|
|
1207
|
+
*/
|
|
1208
|
+
export interface PanelUploadDefaults {
|
|
1209
|
+
/** Abort callback for current upload */
|
|
1210
|
+
abort: (() => void) | null;
|
|
1211
|
+
/** Accepted file types */
|
|
1212
|
+
accept: string;
|
|
1213
|
+
/** Additional file attributes */
|
|
1214
|
+
attributes: Record<string, unknown>;
|
|
1215
|
+
/** Files to upload */
|
|
1216
|
+
files: PanelUploadFile[];
|
|
1217
|
+
/** Maximum number of files */
|
|
1218
|
+
max: number | null;
|
|
1219
|
+
/** Whether multiple files allowed */
|
|
1220
|
+
multiple: boolean;
|
|
1221
|
+
/** File preview data */
|
|
1222
|
+
preview: Record<string, unknown>;
|
|
1223
|
+
/** File being replaced */
|
|
1224
|
+
replacing: PanelUploadFile | null;
|
|
1225
|
+
/** Upload endpoint URL */
|
|
1226
|
+
url: string | null;
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
/**
|
|
1230
|
+
* Upload feature for file handling.
|
|
1231
|
+
*
|
|
1232
|
+
* Manages file selection, upload progress, and completion.
|
|
1233
|
+
* Supports chunked uploads for large files.
|
|
1234
|
+
*
|
|
1235
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/upload.js
|
|
1236
|
+
* @since 4.0.0
|
|
1237
|
+
*/
|
|
1238
|
+
export interface PanelUpload
|
|
1239
|
+
extends PanelState<PanelUploadDefaults>, PanelEventListeners {
|
|
1240
|
+
/** Abort callback for current upload */
|
|
1241
|
+
abort: (() => void) | null;
|
|
1242
|
+
/** Accepted file types */
|
|
1243
|
+
accept: string;
|
|
1244
|
+
/** Additional file attributes */
|
|
1245
|
+
attributes: Record<string, unknown>;
|
|
1246
|
+
/** Files to upload */
|
|
1247
|
+
files: PanelUploadFile[];
|
|
1248
|
+
/** Maximum number of files */
|
|
1249
|
+
max: number | null;
|
|
1250
|
+
/** Whether multiple files allowed */
|
|
1251
|
+
multiple: boolean;
|
|
1252
|
+
/** File preview data */
|
|
1253
|
+
preview: Record<string, unknown>;
|
|
1254
|
+
/** File being replaced */
|
|
1255
|
+
replacing: PanelUploadFile | null;
|
|
1256
|
+
/** Upload endpoint URL */
|
|
1257
|
+
url: string | null;
|
|
1258
|
+
|
|
1259
|
+
/** Hidden file input element */
|
|
1260
|
+
input: HTMLInputElement | null;
|
|
1261
|
+
|
|
1262
|
+
/** Files that completed uploading */
|
|
1263
|
+
readonly completed: PanelUploadFile[];
|
|
1264
|
+
|
|
1265
|
+
/**
|
|
1266
|
+
* Shows success notification and emits model.update.
|
|
1267
|
+
*/
|
|
1268
|
+
announce: () => void;
|
|
1269
|
+
|
|
1270
|
+
/**
|
|
1271
|
+
* Cancels current upload and resets state.
|
|
1272
|
+
*/
|
|
1273
|
+
cancel: () => Promise<void>;
|
|
1274
|
+
|
|
1275
|
+
/**
|
|
1276
|
+
* Called when upload dialog submit clicked.
|
|
1277
|
+
*/
|
|
1278
|
+
done: () => Promise<void>;
|
|
1279
|
+
|
|
1280
|
+
/**
|
|
1281
|
+
* Finds duplicate file by comparing properties.
|
|
1282
|
+
*
|
|
1283
|
+
* @param file - File to check
|
|
1284
|
+
*/
|
|
1285
|
+
findDuplicate: (file: File) => PanelUploadFile | undefined;
|
|
1286
|
+
|
|
1287
|
+
/**
|
|
1288
|
+
* Checks if file has a unique name.
|
|
1289
|
+
*
|
|
1290
|
+
* @param file - File to check
|
|
1291
|
+
*/
|
|
1292
|
+
hasUniqueName: (file: File) => boolean;
|
|
1293
|
+
|
|
1294
|
+
/**
|
|
1295
|
+
* Converts File to enriched upload file object.
|
|
1296
|
+
*
|
|
1297
|
+
* @param file - File to convert
|
|
1298
|
+
*/
|
|
1299
|
+
file: (file: File) => PanelUploadFile;
|
|
1300
|
+
|
|
1301
|
+
/**
|
|
1302
|
+
* Opens file upload dialog.
|
|
1303
|
+
*
|
|
1304
|
+
* @param files - Initial files
|
|
1305
|
+
* @param options - Upload options
|
|
1306
|
+
*/
|
|
1307
|
+
open: (
|
|
1308
|
+
files?: File[] | FileList,
|
|
1309
|
+
options?: Partial<PanelUploadDefaults>,
|
|
1310
|
+
) => void;
|
|
1311
|
+
|
|
1312
|
+
/**
|
|
1313
|
+
* Opens system file picker.
|
|
1314
|
+
*
|
|
1315
|
+
* @param options - Upload options
|
|
1316
|
+
*/
|
|
1317
|
+
pick: (options?: Partial<PanelUploadDefaults>) => void;
|
|
1318
|
+
|
|
1319
|
+
/**
|
|
1320
|
+
* Removes a file from the list.
|
|
1321
|
+
*
|
|
1322
|
+
* @param id - File ID to remove
|
|
1323
|
+
*/
|
|
1324
|
+
remove: (id: string) => void;
|
|
1325
|
+
|
|
1326
|
+
/**
|
|
1327
|
+
* Opens picker to replace an existing file.
|
|
1328
|
+
*
|
|
1329
|
+
* @param file - File to replace
|
|
1330
|
+
* @param options - Upload options
|
|
1331
|
+
*/
|
|
1332
|
+
replace: (
|
|
1333
|
+
file: PanelUploadFile,
|
|
1334
|
+
options?: Partial<PanelUploadDefaults>,
|
|
1335
|
+
) => void;
|
|
1336
|
+
|
|
1337
|
+
/**
|
|
1338
|
+
* Adds files to upload list with deduplication.
|
|
1339
|
+
*
|
|
1340
|
+
* @param files - Files to add
|
|
1341
|
+
* @param options - Upload options
|
|
1342
|
+
*/
|
|
1343
|
+
select: (
|
|
1344
|
+
files: File[] | FileList,
|
|
1345
|
+
options?: Partial<PanelUploadDefaults>,
|
|
1346
|
+
) => void;
|
|
1347
|
+
|
|
1348
|
+
/**
|
|
1349
|
+
* Sets state and registers event listeners.
|
|
1350
|
+
*/
|
|
1351
|
+
set: (state: Partial<PanelUploadDefaults>) => PanelUploadDefaults;
|
|
1352
|
+
|
|
1353
|
+
/**
|
|
1354
|
+
* Submits and uploads all remaining files.
|
|
1355
|
+
*/
|
|
1356
|
+
submit: () => Promise<void>;
|
|
1357
|
+
|
|
1358
|
+
/**
|
|
1359
|
+
* Uploads a single file with chunking support.
|
|
1360
|
+
*
|
|
1361
|
+
* @param file - File to upload
|
|
1362
|
+
* @param attributes - Additional attributes
|
|
1363
|
+
*/
|
|
1364
|
+
upload: (
|
|
1365
|
+
file: PanelUploadFile,
|
|
1366
|
+
attributes?: Record<string, unknown>,
|
|
1367
|
+
) => Promise<void>;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
// -----------------------------------------------------------------------------
|
|
1371
|
+
// Events
|
|
1372
|
+
// -----------------------------------------------------------------------------
|
|
1373
|
+
|
|
1374
|
+
/**
|
|
1375
|
+
* Keychain modifier string (e.g., `'cmd.shift.s'`).
|
|
1376
|
+
*/
|
|
1377
|
+
export type PanelKeychain = string;
|
|
1378
|
+
|
|
1379
|
+
/**
|
|
1380
|
+
* Event emitter interface (mitt-compatible).
|
|
1381
|
+
*/
|
|
1382
|
+
export interface PanelEventEmitter {
|
|
1383
|
+
emit: (event: string, ...args: unknown[]) => void;
|
|
1384
|
+
on: (event: string, handler: (...args: unknown[]) => void) => void;
|
|
1385
|
+
off: (event: string, handler?: (...args: unknown[]) => void) => void;
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
/**
|
|
1389
|
+
* Events feature for global event handling.
|
|
1390
|
+
*
|
|
1391
|
+
* Provides global event subscriptions and keyboard shortcut handling.
|
|
1392
|
+
* Uses mitt for the internal event bus.
|
|
1393
|
+
*
|
|
1394
|
+
* @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/events.js
|
|
1395
|
+
* @since 4.0.0
|
|
1396
|
+
*/
|
|
1397
|
+
export interface PanelEvents extends PanelEventEmitter {
|
|
1398
|
+
/** Internal mitt emitter instance */
|
|
1399
|
+
emitter: PanelEventEmitter;
|
|
1400
|
+
|
|
1401
|
+
/** Element that was entered during drag */
|
|
1402
|
+
entered: Element | null;
|
|
1403
|
+
|
|
1404
|
+
// Global event handlers
|
|
1405
|
+
|
|
1406
|
+
/**
|
|
1407
|
+
* Handles window beforeunload event.
|
|
1408
|
+
*
|
|
1409
|
+
* @param event - BeforeUnloadEvent
|
|
1410
|
+
*/
|
|
1411
|
+
beforeunload: (event: BeforeUnloadEvent) => void;
|
|
1412
|
+
|
|
1413
|
+
/**
|
|
1414
|
+
* Handles document blur event.
|
|
1415
|
+
*
|
|
1416
|
+
* @param event - FocusEvent
|
|
1417
|
+
*/
|
|
1418
|
+
blur: (event: FocusEvent) => void;
|
|
1419
|
+
|
|
1420
|
+
/**
|
|
1421
|
+
* Handles document click event.
|
|
1422
|
+
*
|
|
1423
|
+
* @param event - MouseEvent
|
|
1424
|
+
*/
|
|
1425
|
+
click: (event: MouseEvent) => void;
|
|
1426
|
+
|
|
1427
|
+
/**
|
|
1428
|
+
* Handles clipboard copy event.
|
|
1429
|
+
*
|
|
1430
|
+
* @param event - ClipboardEvent
|
|
1431
|
+
*/
|
|
1432
|
+
copy: (event: ClipboardEvent) => void;
|
|
1433
|
+
|
|
1434
|
+
/**
|
|
1435
|
+
* Handles window dragenter event.
|
|
1436
|
+
*
|
|
1437
|
+
* @param event - DragEvent
|
|
1438
|
+
*/
|
|
1439
|
+
dragenter: (event: DragEvent) => void;
|
|
1440
|
+
|
|
1441
|
+
/**
|
|
1442
|
+
* Handles window dragexit event.
|
|
1443
|
+
*
|
|
1444
|
+
* @param event - DragEvent
|
|
1445
|
+
*/
|
|
1446
|
+
dragexit: (event: DragEvent) => void;
|
|
1447
|
+
|
|
1448
|
+
/**
|
|
1449
|
+
* Handles window dragleave event.
|
|
1450
|
+
*
|
|
1451
|
+
* @param event - DragEvent
|
|
1452
|
+
*/
|
|
1453
|
+
dragleave: (event: DragEvent) => void;
|
|
1454
|
+
|
|
1455
|
+
/**
|
|
1456
|
+
* Handles window dragover event.
|
|
1457
|
+
*
|
|
1458
|
+
* @param event - DragEvent
|
|
1459
|
+
*/
|
|
1460
|
+
dragover: (event: DragEvent) => void;
|
|
1461
|
+
|
|
1462
|
+
/**
|
|
1463
|
+
* Handles window drop event.
|
|
1464
|
+
*
|
|
1465
|
+
* @param event - DragEvent
|
|
1466
|
+
*/
|
|
1467
|
+
drop: (event: DragEvent) => void;
|
|
1468
|
+
|
|
1469
|
+
/**
|
|
1470
|
+
* Handles document focus event.
|
|
1471
|
+
*
|
|
1472
|
+
* @param event - FocusEvent
|
|
1473
|
+
*/
|
|
1474
|
+
focus: (event: FocusEvent) => void;
|
|
1475
|
+
|
|
1476
|
+
/**
|
|
1477
|
+
* Creates keychain modifier string.
|
|
1478
|
+
*
|
|
1479
|
+
* @param type - Event type
|
|
1480
|
+
* @param event - KeyboardEvent
|
|
1481
|
+
* @returns Keychain string (e.g., `'keydown.cmd.shift.s'`)
|
|
1482
|
+
*/
|
|
1483
|
+
keychain: (type: "keydown" | "keyup", event: KeyboardEvent) => PanelKeychain;
|
|
1484
|
+
|
|
1485
|
+
/**
|
|
1486
|
+
* Handles window keydown event.
|
|
1487
|
+
*
|
|
1488
|
+
* @param event - KeyboardEvent
|
|
1489
|
+
*/
|
|
1490
|
+
keydown: (event: KeyboardEvent) => void;
|
|
1491
|
+
|
|
1492
|
+
/**
|
|
1493
|
+
* Handles window keyup event.
|
|
1494
|
+
*
|
|
1495
|
+
* @param event - KeyboardEvent
|
|
1496
|
+
*/
|
|
1497
|
+
keyup: (event: KeyboardEvent) => void;
|
|
1498
|
+
|
|
1499
|
+
/**
|
|
1500
|
+
* Handles offline event.
|
|
1501
|
+
*
|
|
1502
|
+
* @param event - Event
|
|
1503
|
+
*/
|
|
1504
|
+
offline: (event: Event) => void;
|
|
1505
|
+
|
|
1506
|
+
/**
|
|
1507
|
+
* Handles online event.
|
|
1508
|
+
*
|
|
1509
|
+
* @param event - Event
|
|
1510
|
+
*/
|
|
1511
|
+
online: (event: Event) => void;
|
|
1512
|
+
|
|
1513
|
+
/**
|
|
1514
|
+
* Handles clipboard paste event.
|
|
1515
|
+
*
|
|
1516
|
+
* @param event - ClipboardEvent
|
|
1517
|
+
*/
|
|
1518
|
+
paste: (event: ClipboardEvent) => void;
|
|
1519
|
+
|
|
1520
|
+
/**
|
|
1521
|
+
* Handles window popstate event (browser back).
|
|
1522
|
+
*
|
|
1523
|
+
* @param event - PopStateEvent
|
|
1524
|
+
*/
|
|
1525
|
+
popstate: (event: PopStateEvent) => void;
|
|
1526
|
+
|
|
1527
|
+
/**
|
|
1528
|
+
* Prevents event default and propagation.
|
|
1529
|
+
*
|
|
1530
|
+
* @param event - Event to prevent
|
|
1531
|
+
*/
|
|
1532
|
+
prevent: (event: Event) => void;
|
|
1533
|
+
|
|
1534
|
+
/**
|
|
1535
|
+
* Subscribes all global event listeners.
|
|
1536
|
+
*/
|
|
1537
|
+
subscribe: () => void;
|
|
1538
|
+
|
|
1539
|
+
/**
|
|
1540
|
+
* Unsubscribes all global event listeners.
|
|
1541
|
+
*/
|
|
1542
|
+
unsubscribe: () => void;
|
|
1543
|
+
}
|