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 +12 -5
- package/package.json +1 -1
- package/src/blocks.d.ts +27 -42
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](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
|
|
26
|
-
const query: KirbyQuery = '
|
|
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
|
-
|
|
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
package/src/blocks.d.ts
CHANGED
|
@@ -1,51 +1,36 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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 =
|
|
16
|
-
U extends Record<string,
|
|
23
|
+
T extends string = keyof KirbyDefaultBlocks,
|
|
24
|
+
U extends Record<string, unknown> = Record<never, never>,
|
|
17
25
|
> {
|
|
18
|
-
content: U extends Record<string,
|
|
26
|
+
content: U extends Record<string, unknown>
|
|
19
27
|
? U
|
|
20
|
-
: T extends
|
|
21
|
-
?
|
|
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;
|