kirby-types 1.1.2 → 1.2.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.
@@ -17,7 +17,7 @@
17
17
  export interface PanelArraySearchOptions {
18
18
  /** Minimum query length (default: 0) */
19
19
  min?: number;
20
- /** Field to search in (default: `'text'`) */
20
+ /** Field to search in (default: `"text"`) */
21
21
  field?: string;
22
22
  /** Maximum results to return */
23
23
  limit?: number;
@@ -173,8 +173,8 @@ export interface PanelHelpersString {
173
173
  *
174
174
  * @param string - String to convert
175
175
  * @param rules - Language/ASCII conversion rules
176
- * @param allowed - Allowed characters (default: `'a-z0-9'`)
177
- * @param separator - Separator character (default: `'-'`)
176
+ * @param allowed - Allowed characters (default: `"a-z0-9"`)
177
+ * @param separator - Separator character (default: `"-"`)
178
178
  * @returns Slug string
179
179
  */
180
180
  slug: (
@@ -417,17 +417,18 @@ export interface PanelHelpersClipboard {
417
417
  *
418
418
  * @param event - ClipboardEvent or string
419
419
  * @param plain - Read as plain text only
420
- * @returns Clipboard content
420
+ * @returns Clipboard content or null if empty
421
421
  */
422
- read: (event: ClipboardEvent | string, plain?: boolean) => string;
422
+ read: (event: ClipboardEvent | string, plain?: boolean) => string | null;
423
423
 
424
424
  /**
425
425
  * Writes to clipboard. Objects are auto-JSONified.
426
426
  *
427
427
  * @param value - Value to write
428
428
  * @param event - ClipboardEvent for event-based writing
429
+ * @returns True if successful
429
430
  */
430
- write: (value: any, event?: ClipboardEvent) => void;
431
+ write: (value: any, event?: ClipboardEvent) => boolean;
431
432
  }
432
433
 
433
434
  // -----------------------------------------------------------------------------
@@ -445,27 +446,27 @@ export interface PanelHelpersEmbed {
445
446
  *
446
447
  * @param url - YouTube video URL
447
448
  * @param doNotTrack - Enable privacy-enhanced mode
448
- * @returns Embed URL or null
449
+ * @returns Embed URL or false if not valid
449
450
  */
450
- youtube: (url: string, doNotTrack?: boolean) => string | null;
451
+ youtube: (url: string, doNotTrack?: boolean) => string | false;
451
452
 
452
453
  /**
453
454
  * Converts Vimeo URL to embed URL.
454
455
  *
455
456
  * @param url - Vimeo video URL
456
457
  * @param doNotTrack - Enable do-not-track mode
457
- * @returns Embed URL or null
458
+ * @returns Embed URL or false if not valid
458
459
  */
459
- vimeo: (url: string, doNotTrack?: boolean) => string | null;
460
+ vimeo: (url: string, doNotTrack?: boolean) => string | false;
460
461
 
461
462
  /**
462
463
  * Auto-detects provider and converts to embed URL.
463
464
  *
464
465
  * @param url - Video URL
465
466
  * @param doNotTrack - Privacy mode
466
- * @returns Embed URL or null
467
+ * @returns Embed URL or false if not valid
467
468
  */
468
- video: (url: string, doNotTrack?: boolean) => string | null;
469
+ video: (url: string, doNotTrack?: boolean) => string | false;
469
470
  }
470
471
 
471
472
  // -----------------------------------------------------------------------------
@@ -485,7 +486,7 @@ export interface PanelFieldDefinition {
485
486
  /** Conditional visibility */
486
487
  when?: Record<string, any>;
487
488
  /** API endpoint */
488
- endpoints?: { field?: string; section?: string };
489
+ endpoints?: { field?: string; section?: string; model?: string };
489
490
  /** Nested fields */
490
491
  fields?: Record<string, PanelFieldDefinition>;
491
492
  /** Additional properties */
@@ -569,7 +570,7 @@ export interface PanelHelpersFile {
569
570
  * Formats byte size as human-readable string.
570
571
  *
571
572
  * @param size - Size in bytes
572
- * @returns Formatted size (e.g., `'1.2 MB'`)
573
+ * @returns Formatted size (e.g., `"1.2 MB"`)
573
574
  */
574
575
  niceSize: (size: number) => string;
575
576
  }
@@ -587,7 +588,7 @@ export interface PanelHelpersKeyboard {
587
588
  /**
588
589
  * Returns the meta key name for the current OS.
589
590
  *
590
- * @returns 'cmd' on Mac, 'ctrl' on other OS
591
+ * @returns `"cmd"` on Mac, `"ctrl"` on other OS
591
592
  */
592
593
  metaKey: () => "cmd" | "ctrl";
593
594
  }
@@ -651,12 +652,12 @@ export interface PanelHelpersLink {
651
652
  *
652
653
  * @param value - Link value to detect
653
654
  * @param types - Custom type definitions
654
- * @returns Detection result
655
+ * @returns Detection result or undefined if no match
655
656
  */
656
657
  detect: (
657
658
  value: string,
658
659
  types?: Record<string, PanelLinkType>,
659
- ) => PanelLinkDetection;
660
+ ) => PanelLinkDetection | undefined;
660
661
 
661
662
  /**
662
663
  * Converts file permalink to file:// UUID.
@@ -719,14 +720,18 @@ export interface PanelHelpersLink {
719
720
  * Page status button props.
720
721
  */
721
722
  export interface PanelPageStatusProps {
722
- /** Status text */
723
- text: string;
723
+ /** Status title */
724
+ title: string;
724
725
  /** Status icon */
725
726
  icon: string;
726
727
  /** Status color */
727
728
  theme?: string;
728
729
  /** Whether disabled */
729
730
  disabled?: boolean;
731
+ /** Button size */
732
+ size: string;
733
+ /** Button style */
734
+ style: string;
730
735
  }
731
736
 
732
737
  /**
@@ -775,9 +780,9 @@ export type PanelUploadCompleteCallback = (
775
780
  export interface PanelUploadParams {
776
781
  /** Upload endpoint URL */
777
782
  url: string;
778
- /** HTTP method (default: `'POST'`) */
783
+ /** HTTP method (default: `"POST"`) */
779
784
  method?: string;
780
- /** Form field name (default: `'file'`) */
785
+ /** Form field name (default: `"file"`) */
781
786
  field?: string;
782
787
  /** Override filename */
783
788
  filename?: string;
@@ -822,10 +827,17 @@ export interface PanelThrottleOptions {
822
827
  }
823
828
 
824
829
  /**
825
- * Debounced/throttled function with cancel method.
830
+ * Debounced function (without cancel method).
826
831
  */
827
832
  export interface PanelDebouncedFunction<T extends (...args: any[]) => any> {
828
833
  (...args: Parameters<T>): ReturnType<T> | undefined;
834
+ }
835
+
836
+ /**
837
+ * Throttled function with cancel method.
838
+ */
839
+ export interface PanelThrottledFunction<T extends (...args: any[]) => any> {
840
+ (...args: Parameters<T>): ReturnType<T> | undefined;
829
841
  /** Cancels pending invocation */
830
842
  cancel: () => void;
831
843
  }
@@ -861,7 +873,7 @@ export type PanelComparator = (a: string, b: string) => number;
861
873
  * @example
862
874
  * ```ts
863
875
  * // In a Vue component
864
- * this.$helper.string.slug('Hello World');
876
+ * this.$helper.string.slug("Hello World");
865
877
  * this.$helper.clone(someObject);
866
878
  * this.$helper.uuid();
867
879
  * ```
@@ -885,9 +897,9 @@ export interface PanelHelpers {
885
897
  * Resolves CSS color to CSS variable.
886
898
  *
887
899
  * @param value - Color name or value
888
- * @returns CSS variable or original value
900
+ * @returns CSS variable or original value, undefined if not a string
889
901
  */
890
- color: (value: string) => string;
902
+ color: (value: string) => string | undefined;
891
903
 
892
904
  /**
893
905
  * Creates a debounced function.
@@ -917,8 +929,9 @@ export interface PanelHelpers {
917
929
  *
918
930
  * @param element - Selector or element
919
931
  * @param field - Specific input name to focus
932
+ * @returns The focused element, or false if nothing could be focused
920
933
  */
921
- focus: (element: string | HTMLElement, field?: string) => void;
934
+ focus: (element: string | HTMLElement, field?: string) => HTMLElement | false;
922
935
 
923
936
  /**
924
937
  * Checks if component is registered globally.
@@ -957,8 +970,8 @@ export interface PanelHelpers {
957
970
  /**
958
971
  * Converts aspect ratio to percentage.
959
972
  *
960
- * @param fraction - Ratio string (e.g., `'3/2'`)
961
- * @param fallback - Fallback value (default: `'100%'`)
973
+ * @param fraction - Ratio string (e.g., `"3/2"`)
974
+ * @param fallback - Fallback value (default: `"100%"`)
962
975
  * @param vertical - Calculate for vertical orientation
963
976
  * @returns Percentage string
964
977
  */
@@ -998,7 +1011,7 @@ export interface PanelHelpers {
998
1011
  fn: T,
999
1012
  delay: number,
1000
1013
  options?: PanelThrottleOptions,
1001
- ) => PanelDebouncedFunction<T>;
1014
+ ) => PanelThrottledFunction<T>;
1002
1015
 
1003
1016
  /**
1004
1017
  * Uploads a file via XMLHttpRequest.
@@ -215,6 +215,7 @@ export type {
215
215
  PanelDebounceOptions,
216
216
  PanelThrottleOptions,
217
217
  PanelDebouncedFunction,
218
+ PanelThrottledFunction,
218
219
  PanelSortOptions,
219
220
  PanelComparator,
220
221
  // Main Helpers Interface
@@ -236,11 +237,13 @@ export type {
236
237
  PanelLibraryColors,
237
238
  // Dayjs Types
238
239
  PanelDayjsISOFormat,
240
+ PanelDayjsRoundUnit,
241
+ PanelDayjsMergeUnit,
239
242
  PanelDayjsPatternPart,
240
243
  PanelDayjsPattern,
244
+ PanelDayjsExtensions,
241
245
  PanelDayjsInstance,
242
- PanelDayjsInput,
243
- PanelDayjsUnit,
246
+ PanelDayjsStaticExtensions,
244
247
  PanelLibraryDayjs,
245
248
  // Autosize
246
249
  PanelLibraryAutosize,
@@ -275,13 +278,15 @@ export type {
275
278
  * @example
276
279
  * ```ts
277
280
  * // In a Vue component
278
- * const slug = this.$helper.slug('My Page Title');
279
- * const date = this.$library.dayjs('2024-01-15').format('DD.MM.YYYY');
281
+ * const slug = this.$helper.slug("My Page Title");
282
+ * const date = this.$library.dayjs("2024-01-15").format("DD.MM.YYYY");
280
283
  * ```
281
284
  */
282
285
  export type PanelApp = InstanceType<VueConstructor> & {
283
286
  $library: PanelLibrary;
284
287
  $helper: PanelHelpers;
288
+ /** Shortcut for escaping HTML (alias for `$helper.string.escapeHTML`) */
289
+ $esc: (string: string) => string;
285
290
  };
286
291
 
287
292
  // =============================================================================
@@ -467,6 +472,27 @@ export interface PanelUrls {
467
472
  site: string;
468
473
  }
469
474
 
475
+ // =============================================================================
476
+ // Panel Request Response
477
+ // =============================================================================
478
+
479
+ /**
480
+ * Response object from Panel requests.
481
+ *
482
+ * @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/request.js
483
+ */
484
+ export interface PanelRequestResponse {
485
+ /** The original Request object */
486
+ request: Request;
487
+ /** The parsed response */
488
+ response: {
489
+ /** Parsed JSON data */
490
+ json: any;
491
+ /** Raw response text */
492
+ text: string;
493
+ };
494
+ }
495
+
470
496
  // =============================================================================
471
497
  // Panel Plugins
472
498
  // =============================================================================
@@ -498,66 +524,80 @@ export type PanelPluginsViews = Record<string, Record<string, any>>;
498
524
  * Panel plugin system.
499
525
  *
500
526
  * Manages Vue components, icons, and extensions registered by plugins.
527
+ * Properties are ordered to match `panel/public/js/plugins.js`.
501
528
  *
502
529
  * @see https://getkirby.com/docs/reference/plugins/extensions
503
530
  */
504
531
  export interface PanelPlugins {
532
+ // ---------------------------------------------------------------------------
533
+ // Helper Functions (from panel/src/panel/plugins.js)
534
+ // ---------------------------------------------------------------------------
535
+
505
536
  /**
506
- * Resolves component extensions by name.
537
+ * Resolves a component extension if defined as component name.
538
+ *
539
+ * @param app - Vue application instance
540
+ * @param name - Component name being registered
541
+ * @param component - Component options object
542
+ * @returns Updated/extended component options
507
543
  */
508
- resolveComponentExtension: (
509
- name: string,
510
- extension: string,
511
- fallback?: any,
512
- ) => any;
544
+ resolveComponentExtension: (app: any, name: string, component: any) => any;
513
545
 
514
546
  /**
515
- * Resolves all mixins for a component.
547
+ * Resolves available mixins if they are defined.
548
+ *
549
+ * @param component - Component options object
550
+ * @returns Updated component options with resolved mixins
516
551
  */
517
- resolveComponentMixins: (name: string) => any[];
552
+ resolveComponentMixins: (component: any) => any;
518
553
 
519
554
  /**
520
- * Resolves the render function for a component.
555
+ * Resolves a component's competing template/render options.
556
+ *
557
+ * @param component - Component options object
558
+ * @returns Updated component options
521
559
  */
522
- resolveComponentRender: (name: string) => any;
560
+ resolveComponentRender: (component: any) => any;
561
+
562
+ // ---------------------------------------------------------------------------
563
+ // Plugin Data (ordered as in panel/public/js/plugins.js)
564
+ // ---------------------------------------------------------------------------
523
565
 
524
566
  /** Registered Vue components */
525
567
  components: Record<string, ComponentPublicInstance>;
526
568
 
527
- /** Hooks to run after Panel creation */
569
+ /** Callbacks to run after Panel creation */
528
570
  created: Array<() => void>;
529
571
 
530
572
  /** Registered SVG icons */
531
573
  icons: Record<string, string>;
532
574
 
533
- /** Custom login component */
575
+ /** Custom login component (set dynamically by plugins) */
534
576
  login: ComponentPublicInstance | null;
535
577
 
536
- /** Custom textarea buttons */
578
+ /** Registered Panel routes */
579
+ routes: Record<string, any>[];
580
+
581
+ /** Registered textarea toolbar buttons */
537
582
  textareaButtons: Record<string, Record<string, any>>;
538
583
 
539
- /** Third-party plugin data */
584
+ /** Registered third-party plugin data */
540
585
  thirdParty: PanelPluginsThirdParty;
541
586
 
542
- /**
543
- * Registers plugins with the Panel.
544
- */
545
- use: (plugins: Record<string, any>) => any[];
587
+ /** Installed Vue plugins via `Vue.use()` */
588
+ use: any[];
546
589
 
547
- /** Custom view buttons */
590
+ /** Registered view buttons */
548
591
  viewButtons: PanelPluginsViewButtons;
549
592
 
550
- /** Custom writer marks */
593
+ /** Registered Panel views */
594
+ views: PanelPluginsViews;
595
+
596
+ /** Registered writer marks */
551
597
  writerMarks: Record<string, Record<string, any>>;
552
598
 
553
- /** Custom writer nodes */
599
+ /** Registered writer nodes */
554
600
  writerNodes: PanelPluginsWriterNodes;
555
-
556
- /** Custom routes */
557
- routes: Array<Record<string, any>>;
558
-
559
- /** Custom views */
560
- views: PanelPluginsViews;
561
601
  }
562
602
 
563
603
  // =============================================================================
@@ -568,7 +608,7 @@ export interface PanelPlugins {
568
608
  * Language information for multi-language sites.
569
609
  */
570
610
  export interface PanelLanguageInfo {
571
- /** Language code (e.g., `'en'`, `'de'`) */
611
+ /** Language code (e.g., `"en"`, `"de"`) */
572
612
  code: string;
573
613
  /** Whether this is the default language */
574
614
  default: boolean;
@@ -589,7 +629,6 @@ export interface PanelLanguageInfo {
589
629
  */
590
630
  export interface PanelGlobalState {
591
631
  activation: PanelFeatures.PanelActivationDefaults;
592
- content: Record<string, any>;
593
632
  dialog: PanelFeatures.PanelDialogDefaults;
594
633
  drag: PanelFeatures.PanelDragDefaults;
595
634
  drawer: PanelFeatures.PanelDrawerDefaults;
@@ -620,13 +659,13 @@ export interface PanelGlobalState {
620
659
  * const panel = window.$panel;
621
660
  *
622
661
  * // Navigate to a page
623
- * await panel.view.open('/pages/home');
662
+ * await panel.view.open("/pages/home");
624
663
  *
625
664
  * // Open a dialog
626
- * await panel.dialog.open('/dialogs/pages/create');
665
+ * await panel.dialog.open("/dialogs/pages/create");
627
666
  *
628
667
  * // Make an API request
629
- * const data = await panel.get('/api/pages/home');
668
+ * const data = await panel.get("/api/pages/home");
630
669
  * ```
631
670
  *
632
671
  * @see https://github.com/getkirby/kirby/blob/main/panel/src/panel/panel.js
@@ -775,8 +814,12 @@ export interface Panel {
775
814
  *
776
815
  * @param error - Error or message
777
816
  * @param openNotification - Whether to show notification (default: true)
817
+ * @returns Notification state if opened, void otherwise
778
818
  */
779
- error: (error: Error | string, openNotification?: boolean) => void;
819
+ error: (
820
+ error: Error | string,
821
+ openNotification?: boolean,
822
+ ) => void | PanelFeatures.PanelNotificationDefaults;
780
823
 
781
824
  /**
782
825
  * Sends a GET request through the Panel router.
@@ -788,26 +831,29 @@ export interface Panel {
788
831
  get: (url: string | URL, options?: PanelRequestOptions) => Promise<any>;
789
832
 
790
833
  /**
791
- * Opens a URL through the Panel router.
834
+ * Opens a URL through the Panel router and sets the state.
835
+ *
836
+ * Unlike `get()`, this method also updates the Panel state
837
+ * based on the response.
792
838
  *
793
- * @param url - URL to open
839
+ * @param url - URL to open or state object
794
840
  * @param options - Request options
841
+ * @returns The new Panel state
795
842
  */
796
- open: (url: string | URL, options?: PanelRequestOptions) => Promise<void>;
843
+ open: (
844
+ url: string | URL | Partial<PanelGlobalState>,
845
+ options?: PanelRequestOptions,
846
+ ) => Promise<PanelGlobalState>;
797
847
 
798
848
  /**
799
- * Returns all open overlay contexts.
849
+ * Returns all open overlay types.
800
850
  *
801
- * @returns Array of contexts ('view', 'dialog', 'drawer')
802
- */
803
- overlays: () => PanelContext[];
804
-
805
- /**
806
- * Registers a plugin or plugin module.
851
+ * Returns an array of currently open overlays in order.
852
+ * Only includes "drawer" and "dialog" - the view is not an overlay.
807
853
  *
808
- * @param args - Plugin arguments
854
+ * @returns Array of open overlay types
809
855
  */
810
- plugin: (...args: any[]) => void;
856
+ overlays: () => ("drawer" | "dialog")[];
811
857
 
812
858
  /**
813
859
  * Sends a POST request through the Panel router.
@@ -840,28 +886,39 @@ export interface Panel {
840
886
  /**
841
887
  * Sends a request through the Panel router.
842
888
  *
889
+ * Returns an object with both the request and parsed response,
890
+ * or `false` if the request was redirected externally.
891
+ *
843
892
  * @param url - URL to request
844
893
  * @param options - Request options including method
845
- * @returns Fetch Response
894
+ * @returns Request/response object or false on redirect
846
895
  */
847
896
  request: (
848
897
  url: string | URL,
849
898
  options?: PanelRequestOptions,
850
- ) => Promise<Response>;
899
+ ) => Promise<PanelRequestResponse | false>;
851
900
 
852
901
  /**
853
- * Performs a search.
902
+ * Opens the search dialog or performs a search query.
903
+ *
904
+ * When called without a query, opens the search dialog
905
+ * with the specified search type pre-selected.
906
+ *
907
+ * When called with a query, performs the search and returns results.
854
908
  *
855
909
  * @param type - Search type ('pages', 'files', 'users')
856
- * @param query - Search query
857
- * @param options - Request options
858
- * @returns Search results
910
+ * @param query - Search query string
911
+ * @param options - Search options (page, limit)
912
+ * @returns Search results when query provided, void otherwise
859
913
  */
860
- search: (
861
- type: string,
862
- query: string,
863
- options?: PanelRequestOptions,
864
- ) => Promise<any>;
914
+ search: {
915
+ (type: string): void;
916
+ (
917
+ type: string,
918
+ query: string,
919
+ options?: PanelFeatures.PanelSearchOptions,
920
+ ): Promise<PanelFeatures.PanelSearchResult>;
921
+ };
865
922
 
866
923
  /**
867
924
  * Sets global Panel state.
@@ -953,7 +1010,7 @@ export interface PanelViewPropsVersions {
953
1010
  export interface PanelViewPropsTab {
954
1011
  label: string;
955
1012
  icon: string;
956
- columns: Array<Record<string, any>>;
1013
+ columns: Record<string, any>[];
957
1014
  link: string;
958
1015
  name: string;
959
1016
  }
@@ -1009,7 +1066,7 @@ export interface PanelViewProps {
1009
1066
  link: string;
1010
1067
  lock: PanelViewPropsLock;
1011
1068
  permissions: PanelViewPropsPermissions;
1012
- tabs: Array<Record<string, any>>;
1069
+ tabs: Record<string, any>[];
1013
1070
  uuid: string;
1014
1071
  versions: PanelViewPropsVersions;
1015
1072
  tab: PanelViewPropsTab;