kirby-types 1.4.8 → 1.5.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kirby-types",
3
3
  "type": "module",
4
- "version": "1.4.8",
4
+ "version": "1.5.0",
5
5
  "packageManager": "pnpm@10.33.2",
6
6
  "description": "TypeScript types for Kirby Panel plugins and headless CMS usage",
7
7
  "author": "Johann Schopplich <hello@johannschopplich.com>",
@@ -3,7 +3,6 @@
3
3
  *
4
4
  * Provides types for the Panel API client and its resource modules.
5
5
  *
6
- * @see https://github.com/getkirby/kirby/tree/main/panel/src/api
7
6
  * @since 4.0.0
8
7
  */
9
8
 
@@ -99,7 +98,6 @@ export interface PanelApiLoginData {
99
98
  /**
100
99
  * Authentication API methods.
101
100
  *
102
- * @see https://github.com/getkirby/kirby/blob/main/panel/src/api/auth.js
103
101
  * @source panel/src/api/auth.js
104
102
  */
105
103
  export interface PanelApiAuth {
@@ -141,7 +139,6 @@ export interface PanelApiAuth {
141
139
  /**
142
140
  * Files API methods.
143
141
  *
144
- * @see https://github.com/getkirby/kirby/blob/main/panel/src/api/files.js
145
142
  * @source panel/src/api/files.js
146
143
  */
147
144
  export interface PanelApiFiles {
@@ -247,7 +244,6 @@ export interface PanelApiLanguageData {
247
244
  /**
248
245
  * Languages API methods.
249
246
  *
250
- * @see https://github.com/getkirby/kirby/blob/main/panel/src/api/languages.js
251
247
  * @source panel/src/api/languages.js
252
248
  */
253
249
  export interface PanelApiLanguages {
@@ -277,9 +273,9 @@ export interface PanelApiLanguages {
277
273
  /**
278
274
  * Lists all languages.
279
275
  *
280
- * @returns Array of languages
276
+ * @returns Wrapped Kirby collection response (`{ data, pagination }`)
281
277
  */
282
- list: () => Promise<any[]>;
278
+ list: () => Promise<any>;
283
279
 
284
280
  /**
285
281
  * Updates a language.
@@ -320,7 +316,6 @@ export interface PanelApiPageDuplicateOptions {
320
316
  /**
321
317
  * Pages API methods.
322
318
  *
323
- * @see https://github.com/getkirby/kirby/blob/main/panel/src/api/pages.js
324
319
  * @source panel/src/api/pages.js
325
320
  */
326
321
  export interface PanelApiPages {
@@ -500,7 +495,6 @@ export interface PanelApiPages {
500
495
  /**
501
496
  * Roles API methods.
502
497
  *
503
- * @see https://github.com/getkirby/kirby/blob/main/panel/src/api/roles.js
504
498
  * @source panel/src/api/roles.js
505
499
  */
506
500
  export interface PanelApiRoles {
@@ -516,9 +510,9 @@ export interface PanelApiRoles {
516
510
  * Lists available roles.
517
511
  *
518
512
  * @param params - Query parameters
519
- * @returns Array of roles
513
+ * @returns Wrapped Kirby collection response (`{ data, pagination }`)
520
514
  */
521
- list: (params?: Record<string, any>) => Promise<any[]>;
515
+ list: (params?: Record<string, any>) => Promise<any>;
522
516
  }
523
517
 
524
518
  // -----------------------------------------------------------------------------
@@ -528,7 +522,6 @@ export interface PanelApiRoles {
528
522
  /**
529
523
  * Site API methods.
530
524
  *
531
- * @see https://github.com/getkirby/kirby/blob/main/panel/src/api/site.js
532
525
  * @source panel/src/api/site.js
533
526
  */
534
527
  export interface PanelApiSite {
@@ -604,7 +597,6 @@ export interface PanelApiSystemRegisterData {
604
597
  /**
605
598
  * System API methods.
606
599
  *
607
- * @see https://github.com/getkirby/kirby/blob/main/panel/src/api/system.js
608
600
  * @source panel/src/api/system.js
609
601
  */
610
602
  export interface PanelApiSystem {
@@ -640,7 +632,6 @@ export interface PanelApiSystem {
640
632
  /**
641
633
  * Translations API methods.
642
634
  *
643
- * @see https://github.com/getkirby/kirby/blob/main/panel/src/api/translations.js
644
635
  * @source panel/src/api/translations.js
645
636
  */
646
637
  export interface PanelApiTranslations {
@@ -655,9 +646,9 @@ export interface PanelApiTranslations {
655
646
  /**
656
647
  * Lists all translations.
657
648
  *
658
- * @returns Array of translations
649
+ * @returns Wrapped Kirby collection response (`{ data, pagination }`)
659
650
  */
660
- list: () => Promise<any[]>;
651
+ list: () => Promise<any>;
661
652
  }
662
653
 
663
654
  // -----------------------------------------------------------------------------
@@ -681,7 +672,6 @@ export interface PanelApiUserCreateData {
681
672
  /**
682
673
  * Users API methods.
683
674
  *
684
- * @see https://github.com/getkirby/kirby/blob/main/panel/src/api/users.js
685
675
  * @source panel/src/api/users.js
686
676
  */
687
677
  export interface PanelApiUsers {
@@ -796,17 +786,19 @@ export interface PanelApiUsers {
796
786
  * Queries users via the users/search endpoint.
797
787
  *
798
788
  * @param query - Query parameters
799
- * @returns Array of users
789
+ * @returns Paginated users response
800
790
  */
801
- list: (query?: Record<string, any>) => Promise<any[]>;
791
+ list: (query?: Record<string, any>) => Promise<any>;
802
792
 
803
793
  /**
804
794
  * Gets roles available to a user.
805
795
  *
806
796
  * @param id - User ID
807
- * @returns Array of roles
797
+ * @returns Array of role options shaped for select inputs
808
798
  */
809
- roles: (id: string) => Promise<any[]>;
799
+ roles: (
800
+ id: string,
801
+ ) => Promise<{ info: string; text: string; value: string }[]>;
810
802
 
811
803
  /**
812
804
  * Searches users.
@@ -828,11 +820,11 @@ export interface PanelApiUsers {
828
820
  /**
829
821
  * Gets API URL for a user.
830
822
  *
831
- * @param id - User ID
823
+ * @param id - User ID (null for the users collection root)
832
824
  * @param path - Additional path
833
825
  * @returns API URL
834
826
  */
835
- url: (id: string, path?: string) => string;
827
+ url: (id: string | null, path?: string) => string;
836
828
  }
837
829
 
838
830
  // -----------------------------------------------------------------------------
@@ -857,8 +849,8 @@ export interface PanelApiUsers {
857
849
  * });
858
850
  * ```
859
851
  *
860
- * @see https://github.com/getkirby/kirby/blob/main/panel/src/api/index.js
861
852
  * @source panel/src/api/index.js
853
+ * @source panel/src/api/index.ts
862
854
  * @source panel/src/api/request.js
863
855
  * @source panel/src/api/get.js
864
856
  * @source panel/src/api/post.js
@@ -875,17 +867,20 @@ export interface PanelApi {
875
867
  /** Whether to use method override */
876
868
  methodOverride: boolean;
877
869
 
878
- /** Ping interval ID */
879
- ping: ReturnType<typeof setInterval> | null;
870
+ /** Heartbeat interval ID; populated once the auth ping has been scheduled. */
871
+ pingId: ReturnType<typeof setInterval> | undefined;
872
+
873
+ /**
874
+ * Clears any existing heartbeat and schedules a new auth ping every 5 minutes.
875
+ * @since 6
876
+ */
877
+ ping: () => void;
880
878
 
881
879
  /** Active request IDs */
882
880
  requests: string[];
883
881
 
884
- /** Number of running requests */
885
- running: number;
886
-
887
- /** Current language code (lazily set on first request, or `undefined` before any request has run) */
888
- language: string | undefined;
882
+ /** Current language code (set from the Panel's active language on construction and refreshed on each request) */
883
+ language: string;
889
884
 
890
885
  /**
891
886
  * Makes a raw API request.
@@ -4,7 +4,6 @@
4
4
  * This module provides the foundational types for the Panel's
5
5
  * state management hierarchy: State → Feature → Modal.
6
6
  *
7
- * @see https://github.com/getkirby/kirby/tree/main/panel/src/panel
8
7
  * @since 4.0.0
9
8
  */
10
9
 
@@ -28,8 +27,8 @@
28
27
  * notification.set({ message: "Saved!" });
29
28
  * ```
30
29
  *
31
- * @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/state.js
32
30
  * @source panel/src/panel/state.js
31
+ * @source panel/src/panel/state.ts
33
32
  */
34
33
  export interface PanelState<TDefaults extends object = Record<string, any>> {
35
34
  /**
@@ -46,9 +45,9 @@ export interface PanelState<TDefaults extends object = Record<string, any>> {
46
45
 
47
46
  /**
48
47
  * Restores the default state by calling `set(defaults())`.
49
- * @returns The restored state object
48
+ * @returns K5 returns the restored state object; K6 narrowed the return to void.
50
49
  */
51
- reset: () => TDefaults;
50
+ reset: () => TDefaults | void;
52
51
 
53
52
  /**
54
53
  * Sets a new state, merging with defaults.
@@ -67,73 +66,27 @@ export interface PanelState<TDefaults extends object = Record<string, any>> {
67
66
 
68
67
  /**
69
68
  * Validates that the state is a plain object.
69
+ *
70
70
  * @throws Error if state is not an object
71
+ * @deprecated K6 inlined the check into `set()` and removed the public method – calls on K6 will throw.
71
72
  */
72
73
  validateState: (state: unknown) => boolean;
73
74
  }
74
75
 
75
- // -----------------------------------------------------------------------------
76
- // State Base Types
77
- // -----------------------------------------------------------------------------
78
-
79
- /**
80
- * @internal
81
- * @source panel/src/panel/state.js
82
- */
83
- export interface PanelStateBase {
84
- key: () => string;
85
- defaults: () => Record<string, any>;
86
- reset: () => Record<string, any>;
87
- set: (state: Record<string, any>) => Record<string, any>;
88
- state: () => Record<string, any>;
89
- validateState: (state: unknown) => boolean;
90
- }
91
-
92
- /**
93
- * @internal
94
- * @source panel/src/panel/feature.js
95
- */
96
- export interface PanelFeatureBase extends PanelStateBase, PanelEventListeners {
97
- abortController: AbortController | null;
98
- component: string | null;
99
- isLoading: boolean;
100
- path: string | null;
101
- props: Record<string, any>;
102
- query: Record<string, any>;
103
- referrer: string | null;
104
- timestamp: number | null;
105
- }
106
-
107
- /**
108
- * @internal
109
- * @source panel/src/panel/modal.js
110
- */
111
- export interface PanelModalBase extends PanelFeatureBase {
112
- id: string | null;
113
- isOpen: boolean;
114
- history: PanelHistory;
115
- }
116
-
117
- /**
118
- * @internal
119
- * @source panel/src/panel/history.js
120
- */
121
- export interface PanelHistoryBase {
122
- milestones: PanelHistoryMilestone[];
123
- }
124
-
125
76
  // -----------------------------------------------------------------------------
126
77
  // Event Listeners
127
78
  // -----------------------------------------------------------------------------
128
79
 
129
80
  /**
130
81
  * @source panel/src/panel/listeners.js
82
+ * @source panel/src/panel/listeners.ts
131
83
  */
132
84
  export type PanelEventCallback<TReturn = any> = (...args: any[]) => TReturn;
133
85
 
134
86
  /**
135
87
  * Map of event names to their callback functions.
136
88
  * @source panel/src/panel/listeners.js
89
+ * @source panel/src/panel/listeners.ts
137
90
  */
138
91
  export type PanelEventListenerMap<TEvents extends string = string> = Partial<
139
92
  Record<TEvents, PanelEventCallback>
@@ -157,8 +110,8 @@ export type PanelEventListenerMap<TEvents extends string = string> = Partial<
157
110
  * panel.dialog.emit("submit", formData);
158
111
  * ```
159
112
  *
160
- * @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/listeners.js
161
113
  * @source panel/src/panel/listeners.js
114
+ * @source panel/src/panel/listeners.ts
162
115
  */
163
116
  export interface PanelEventListeners<TEvents extends string = string> {
164
117
  on: PanelEventListenerMap<TEvents>;
@@ -185,12 +138,10 @@ export interface PanelEventListeners<TEvents extends string = string> {
185
138
  *
186
139
  * @param event - Event name to emit
187
140
  * @param args - Arguments to pass to the listener
188
- * @returns Listener result, or a noop function if no listener exists
141
+ * @returns Listener result, or `undefined` when no listener is registered.
142
+ * K5 returned a noop function in that case; K6 dropped the fallback.
189
143
  */
190
- emit: <TReturn = any>(
191
- event: TEvents,
192
- ...args: any[]
193
- ) => TReturn | (() => void);
144
+ emit: <TReturn = any>(event: TEvents, ...args: any[]) => TReturn | undefined;
194
145
 
195
146
  /**
196
147
  * Checks if a listener is registered for an event.
@@ -202,6 +153,21 @@ export interface PanelEventListeners<TEvents extends string = string> {
202
153
 
203
154
  /** Returns all registered listeners. */
204
155
  listeners: () => PanelEventListenerMap<TEvents>;
156
+
157
+ /**
158
+ * Removes the listener registered for `event`.
159
+ *
160
+ * @param event - Event name whose listener should be removed
161
+ * @since 6
162
+ */
163
+ removeEventListener: (event: TEvents) => void;
164
+
165
+ /**
166
+ * Clears every registered listener. Called automatically when feature
167
+ * state is replaced.
168
+ * @since 6
169
+ */
170
+ removeEventListeners: () => void;
205
171
  }
206
172
 
207
173
  // -----------------------------------------------------------------------------
@@ -210,6 +176,7 @@ export interface PanelEventListeners<TEvents extends string = string> {
210
176
 
211
177
  /**
212
178
  * @source panel/src/panel/feature.js
179
+ * @source panel/src/panel/feature.ts
213
180
  */
214
181
  export interface PanelFeatureDefaults {
215
182
  abortController: AbortController | null;
@@ -243,8 +210,8 @@ export interface PanelFeatureDefaults {
243
210
  * await panel.dropdown.open("/dropdowns/pages/home/options");
244
211
  * ```
245
212
  *
246
- * @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/feature.js
247
213
  * @source panel/src/panel/feature.js
214
+ * @source panel/src/panel/feature.ts
248
215
  */
249
216
  export interface PanelFeature<TDefaults extends object = PanelFeatureDefaults>
250
217
  extends PanelState<TDefaults>, PanelEventListeners {
@@ -350,9 +317,9 @@ export interface PanelFeature<TDefaults extends object = PanelFeatureDefaults>
350
317
  * Reloads the feature by re-opening its current URL.
351
318
  *
352
319
  * @param options - Request options
353
- * @returns False if no path exists, otherwise void
320
+ * @returns False if no path exists; K6 forwards the `open()` result, K5 returns void.
354
321
  */
355
- reload: (options?: PanelRequestOptions) => Promise<void | false>;
322
+ reload: (options?: PanelRequestOptions) => Promise<TDefaults | false | void>;
356
323
 
357
324
  /** Creates a full URL object for the current path and query. */
358
325
  url: () => URL;
@@ -365,6 +332,7 @@ export interface PanelFeature<TDefaults extends object = PanelFeatureDefaults>
365
332
  /**
366
333
  * Modal event types for dialogs and drawers.
367
334
  * @source panel/src/panel/modal.js
335
+ * @source panel/src/panel/modal.ts
368
336
  */
369
337
  export type PanelModalEvent =
370
338
  | "cancel"
@@ -378,10 +346,11 @@ export type PanelModalEvent =
378
346
  /**
379
347
  * Bound listener functions returned by `modal.listeners()`.
380
348
  * @source panel/src/panel/modal.js
349
+ * @source panel/src/panel/modal.ts
381
350
  */
382
351
  export interface PanelModalListeners {
383
352
  cancel: () => Promise<void>;
384
- close: (id?: string | boolean) => Promise<void>;
353
+ close: (id?: string | true) => Promise<void>;
385
354
  input: (value: any) => void;
386
355
  submit: (value?: any, options?: PanelRequestOptions) => Promise<any>;
387
356
  success: (response: PanelSuccessResponse) => void;
@@ -391,6 +360,7 @@ export interface PanelModalListeners {
391
360
  /**
392
361
  * Success response from modal submission.
393
362
  * @source panel/src/panel/modal.js
363
+ * @source panel/src/panel/modal.ts
394
364
  */
395
365
  export interface PanelSuccessResponse {
396
366
  message?: string;
@@ -432,8 +402,8 @@ export interface PanelSuccessResponse {
432
402
  * panel.drawer.goTo("previous-drawer-id");
433
403
  * ```
434
404
  *
435
- * @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/modal.js
436
405
  * @source panel/src/panel/modal.js
406
+ * @source panel/src/panel/modal.ts
437
407
  */
438
408
  export interface PanelModal<
439
409
  TDefaults extends object = PanelFeatureDefaults & { id: string | null },
@@ -467,7 +437,7 @@ export interface PanelModal<
467
437
  * @param id - Specific modal ID, `true` to close all, or undefined for current
468
438
  * @returns Promise resolving to the previous modal's state, or void
469
439
  */
470
- close: (id?: string | boolean) => Promise<TDefaults | void>;
440
+ close: (id?: string | true) => Promise<TDefaults | void>;
471
441
 
472
442
  /**
473
443
  * Sets focus to the first focusable input or a specific input.
@@ -514,9 +484,9 @@ export interface PanelModal<
514
484
  * Reloads the modal by closing and reopening at the same URL.
515
485
  *
516
486
  * @param options - Request options
517
- * @returns False if no path exists, otherwise void
487
+ * @returns False if no path exists; K6 forwards the `open()` result, K5 returns void.
518
488
  */
519
- reload: (options?: PanelRequestOptions) => Promise<void | false>;
489
+ reload: (options?: PanelRequestOptions) => Promise<TDefaults | false | void>;
520
490
 
521
491
  /**
522
492
  * Sets modal state, auto-generating an ID if not provided.
@@ -578,6 +548,7 @@ export interface PanelModal<
578
548
  /**
579
549
  * A history milestone representing a saved modal state.
580
550
  * @source panel/src/panel/history.js
551
+ * @source panel/src/helpers/history.ts
581
552
  */
582
553
  export interface PanelHistoryMilestone {
583
554
  id: string;
@@ -601,8 +572,8 @@ export interface PanelHistoryMilestone {
601
572
  * }
602
573
  * ```
603
574
  *
604
- * @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/history.js
605
575
  * @source panel/src/panel/history.js
576
+ * @source panel/src/helpers/history.ts
606
577
  */
607
578
  export interface PanelHistory {
608
579
  milestones: PanelHistoryMilestone[];
@@ -654,6 +625,12 @@ export interface PanelHistory {
654
625
  */
655
626
  has: (id: string) => boolean;
656
627
 
628
+ /**
629
+ * Returns true when more than one milestone is stored.
630
+ * @since 6
631
+ */
632
+ hasPrevious: () => boolean;
633
+
657
634
  /**
658
635
  * Gets the array index of a milestone.
659
636
  *
@@ -701,6 +678,8 @@ export interface PanelHistory {
701
678
  * Options for Panel API requests.
702
679
  * @source panel/src/panel/request.js
703
680
  * @source panel/src/panel/feature.js
681
+ * @source panel/src/panel/request.ts
682
+ * @source panel/src/panel/feature.ts
704
683
  */
705
684
  export interface PanelRequestOptions {
706
685
  headers?: Record<string, string>;
@@ -717,17 +696,18 @@ export interface PanelRequestOptions {
717
696
  /** CSRF token sent as the `x-csrf` header. */
718
697
  csrf?: string | false;
719
698
  /**
720
- * Fiber globals sent as the `x-fiber-globals` header.
699
+ * Globals sent as the `x-panel-globals` header (was `x-fiber-globals` in K5).
721
700
  * Arrays are joined with commas; strings are forwarded as-is.
722
701
  */
723
702
  globals?: string | string[];
724
- /** Referrer path sent as the `x-fiber-referrer` header. */
703
+ /** Referrer path sent as the `x-panel-referrer` header (was `x-fiber-referrer` in K5). */
725
704
  referrer?: string | false;
726
705
  }
727
706
 
728
707
  /**
729
708
  * Extended options for refresh requests.
730
709
  * @source panel/src/panel/feature.js
710
+ * @source panel/src/panel/feature.ts
731
711
  */
732
712
  export interface PanelRefreshOptions extends PanelRequestOptions {
733
713
  /** URL to refresh from (defaults to current URL) */
@@ -742,25 +722,21 @@ export interface PanelRefreshOptions extends PanelRequestOptions {
742
722
  * Panel context indicating which layer is currently active.
743
723
  * Used to determine where notifications appear and which feature has focus.
744
724
  * @source panel/src/panel/panel.js
745
- */
746
- export type PanelContext = "view" | "dialog" | "drawer";
747
-
748
- /**
749
- * Context for notifications indicating where they should appear.
750
- * Matches the active editing layer.
751
725
  * @source panel/src/panel/notification.js
726
+ * @source panel/src/panel/notification.ts
752
727
  */
753
- export type NotificationContext = "view" | "dialog" | "drawer";
728
+ export type PanelContext = "view" | "dialog" | "drawer";
754
729
 
755
730
  /**
756
731
  * Type of notification determining behavior and persistence.
757
- * - `info`: General information, auto-closes
758
- * - `success`: Operation completed, auto-closes
732
+ * Only `error` and `fatal` are written to `state.type`; `success()` and
733
+ * `info()` shortcuts set `theme` (and `icon`) instead of `type`.
759
734
  * - `error`: Operation failed, persists until dismissed
760
735
  * - `fatal`: Critical error, displayed in isolated iframe
761
736
  * @source panel/src/panel/notification.js
737
+ * @source panel/src/panel/notification.ts
762
738
  */
763
- export type NotificationType = "error" | "success" | "fatal" | "info";
739
+ export type NotificationType = "error" | "fatal";
764
740
 
765
741
  /**
766
742
  * Visual theme for notifications.
@@ -768,5 +744,6 @@ export type NotificationType = "error" | "success" | "fatal" | "info";
768
744
  * - `negative`: Red, for errors
769
745
  * - `info`: Blue, for information
770
746
  * @source panel/src/panel/notification.js
747
+ * @source panel/src/panel/notification.ts
771
748
  */
772
749
  export type NotificationTheme = "positive" | "negative" | "info";