kirby-types 0.5.0 → 0.6.1

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![NPM version](https://img.shields.io/npm/v/kirby-types?color=a1b858&label=)](https://www.npmjs.com/package/kirby-types)
4
4
 
5
- A collection of TypeScript types to work with Kirby, mainly in the context of the Kirby Query Language.
5
+ A collection of TypeScript types to work with [Kirby CMS](https://getkirby.com), mainly in the context of the Kirby Query Language.
6
6
 
7
7
  ## Setup
8
8
 
@@ -22,13 +22,19 @@ yarn add -D kirby-types
22
22
  ```ts
23
23
  import type { KirbyQuery } from "kirby-types";
24
24
 
25
- // Strictly typed query for the Kirby Query Language
26
- const query: KirbyQuery = 'kirby.page("about")';
25
+ // Strictly typed query
26
+ const query: KirbyQuery = 'page.children.filterBy("featured", true)';
27
+
28
+ // Invalid queries will throw a type error
29
+ let invalidQuery: KirbyQuery;
30
+ invalidQuery = "unknown"; // Not a valid model
31
+ invalidQuery = 'site("'; // Empty parentheses
32
+ invalidQuery = 'site("value"'; // Missing closing parenthesis
27
33
  ```
28
34
 
29
35
  ## API
30
36
 
31
- Click the type names for complete docs.
37
+ By clicking on a type name, you will be redirected to the corresponding TypeScript definition file.
32
38
 
33
39
  ### Query
34
40
 
@@ -37,8 +43,9 @@ Click the type names for complete docs.
37
43
 
38
44
  ### Blocks
39
45
 
40
- - [`KirbyBlockType`](./src/blocks.d.ts) - Matches any [Kirby block type](https://getkirby.com/docs/reference/panel/blocks).
41
46
  - [`KirbyBlock`](./src/blocks.d.ts) - Matches a [Kirby block](https://getkirby.com/docs/guide/page-builder).
47
+ - [`KirbyDefaultBlockType`](./src/blocks.d.ts) - Matches any [Kirby default block type](https://getkirby.com/docs/reference/panel/blocks).
48
+ - [`KirbyDefaultBlocks`](./src/blocks.d.ts) - Maps each of [Kirby's default block type](https://getkirby.com/docs/reference/panel/blocks) to its corresponding block content.
42
49
 
43
50
  ### Layout
44
51
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kirby-types",
3
3
  "type": "module",
4
- "version": "0.5.0",
4
+ "version": "0.6.1",
5
5
  "packageManager": "pnpm@8.7.0",
6
6
  "description": "A collection of TypeScript types for the Kirby CMS",
7
7
  "author": "Johann Schopplich <pkg@johannschopplich.com>",
package/src/blocks.d.ts CHANGED
@@ -1,51 +1,36 @@
1
- export type KirbyBlockType =
2
- | "code"
3
- | "gallery"
4
- | "heading"
5
- | "image"
6
- | "line"
7
- | "list"
8
- | "markdown"
9
- | "quote"
10
- | "table"
11
- | "text"
12
- | "video";
1
+ export interface KirbyDefaultBlocks {
2
+ code: { code: string; language: string };
3
+ gallery: { images: string[] };
4
+ heading: { level: string; text: string };
5
+ image: {
6
+ location: string;
7
+ image: string[];
8
+ src: string;
9
+ alt: string;
10
+ caption: string;
11
+ link: string;
12
+ ratio: string;
13
+ crop: boolean;
14
+ };
15
+ list: { text: string };
16
+ markdown: { text: string };
17
+ quote: { text: string; citation: string };
18
+ text: { text: string };
19
+ video: { url: string; caption: string };
20
+ }
13
21
 
14
22
  export interface KirbyBlock<
15
- T extends string = KirbyBlockType,
16
- U extends Record<string, any> | undefined = undefined,
23
+ T extends string = keyof KirbyDefaultBlocks,
24
+ U extends Record<string, unknown> = Record<never, never>,
17
25
  > {
18
- content: U extends Record<string, any>
26
+ content: U extends Record<string, unknown>
19
27
  ? U
20
- : T extends "code"
21
- ? { code: string; language: string }
22
- : T extends "gallery"
23
- ? { images: string[] }
24
- : T extends "heading"
25
- ? { level: string; text: string }
26
- : T extends "image"
27
- ? {
28
- location: string;
29
- image: string[];
30
- src: string;
31
- alt: string;
32
- caption: string;
33
- link: string;
34
- ratio: string;
35
- crop: boolean;
36
- }
37
- : T extends "list"
38
- ? { text: string }
39
- : T extends "markdown"
40
- ? { text: string }
41
- : T extends "quote"
42
- ? { text: string; citation: string }
43
- : T extends "text"
44
- ? { text: string }
45
- : T extends "video"
46
- ? { url: string; caption: string }
28
+ : T extends keyof KirbyDefaultBlocks
29
+ ? KirbyDefaultBlocks[T]
47
30
  : Record<string, never>;
48
31
  id: string;
49
32
  isHidden: boolean;
50
33
  type: T;
51
34
  }
35
+
36
+ export type KirbyDefaultBlockType = keyof KirbyDefaultBlocks;