kirby-types 1.4.5 → 1.4.6

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
@@ -5,12 +5,22 @@
5
5
 
6
6
  A collection of TypeScript types for [Kirby CMS](https://getkirby.com).
7
7
 
8
- [Panel types](#panel-types) •
9
- [Backend API types](#backend-types) •
10
- [Block and layout types](#layouts)
8
+ [Quick Start](#quick-start) •
9
+ [Common Patterns](#common-patterns) •
10
+ [Panel Types](#panel-types)
11
+ [API Reference](#api-reference)
11
12
 
12
13
  </div>
13
14
 
15
+ ## When to Use
16
+
17
+ | Use Case | Types to Import |
18
+ | ------------------------------------------------------------ | ----------------------------------------------- |
19
+ | **Fetching page data** from Kirby's API | `KirbyApiResponse`, `KirbyBlock`, `KirbyLayout` |
20
+ | **Building KQL queries** with type safety | `KirbyQueryRequest`, `KirbyQueryResponse` |
21
+ | **Developing Panel plugins** (Vue components, custom fields) | `Panel`, `PanelApi` |
22
+ | **Creating Writer extensions** (rich text editor) | `WriterMarkExtension`, `WriterNodeExtension` |
23
+
14
24
  ## Setup
15
25
 
16
26
  ```bash
@@ -24,189 +34,48 @@ npm i -D kirby-types
24
34
  yarn add -D kirby-types
25
35
  ```
26
36
 
27
- ## Features
28
-
29
- <table>
30
- <tr>
31
- <th>🪟 Panel Types</th>
32
- <th>🔌 Backend Types</th>
33
- </tr>
34
- <tr>
35
- <td>
36
-
37
- - **Panel API**: Complete API client method types.
38
- - **State Management**: State, Feature, and Modal hierarchies.
39
- - **Features**: Views, dialogs, drawers, notifications, uploads, and more.
40
- - **Helpers**: Array, string, object, URL, and other utility types.
41
- - **Libraries**: Color manipulation, dayjs, and autosize types.
42
- - **Writer**: ProseMirror-based rich text editor utilities.
43
-
44
- </td>
45
- <td>
46
-
47
- - **API Response**: Type-safe API responses.
48
- - **Blueprints**: Field definitions, fieldsets, and field options.
49
- - **Blocks**: All 11 default block types with content structures.
50
- - **Layouts**: Layout and column types with width unions.
51
- - **KQL**: Query Language request/response types.
52
- - **Query Parsing**: Parse query strings into structured objects at the type level.
53
-
54
- </td>
55
- </tr>
56
- </table>
57
-
58
- ## Basic Usage
59
-
60
- ### Panel Types
61
-
62
- Type the global `window.panel` object for Panel plugin development:
63
-
64
- ```ts
65
- import type { Panel } from "kirby-types";
66
-
67
- // Augment the global Window interface
68
- declare global {
69
- interface Window {
70
- panel: Panel;
71
- }
72
- }
73
-
74
- // Now window.panel is fully typed
75
- window.panel.notification.success("Page saved!");
76
- window.panel.dialog.open("pages/create");
77
- ```
78
-
79
- Common Panel operations with full type safety:
80
-
81
- ```ts
82
- // Notifications
83
- window.panel.notification.success("Changes saved");
84
- window.panel.notification.error("Something went wrong");
85
-
86
- // Theme
87
- window.panel.theme.set("dark");
88
- const currentTheme = window.panel.theme.current; // "light" | "dark"
89
-
90
- // Navigation
91
- await window.panel.view.open("/pages/blog");
92
- await window.panel.dialog.open("/dialogs/pages/create");
93
-
94
- // API calls
95
- const page = await window.panel.api.pages.read("blog");
96
- await window.panel.api.pages.update("blog", { title: "New Title" });
97
-
98
- // Content state
99
- const hasChanges = window.panel.content.hasChanges;
100
- await window.panel.content.save();
101
-
102
- // User info
103
- const user = window.panel.user;
104
- console.log(user.email, user.role);
105
- ```
106
-
107
- ### API Responses
37
+ ## Quick Start
108
38
 
109
- ```ts
110
- import type { KirbyApiResponse } from "kirby-types";
111
-
112
- interface PageData {
113
- id: string;
114
- title: string;
115
- url: string;
116
- }
117
-
118
- const response: KirbyApiResponse<PageData> = {
119
- code: 200,
120
- status: "ok",
121
- result: {
122
- id: "home",
123
- title: "Home",
124
- url: "/",
125
- },
126
- };
127
- ```
128
-
129
- ### Blueprints
130
-
131
- Types for field props and fieldsets as returned by Kirby's `Field->toArray()` and `Fieldset->toArray()`:
39
+ ### Typing KQL Responses
132
40
 
133
41
  ```ts
134
- import type {
135
- KirbyFieldProps,
136
- KirbyFieldsetProps,
137
- KirbyOption,
138
- KirbyTextFieldProps,
139
- } from "kirby-types";
140
-
141
- // Base field props (returned by Field->toArray())
142
- const field: KirbyFieldProps = {
143
- name: "title",
144
- type: "text",
145
- label: "Title",
146
- required: true,
147
- disabled: false,
148
- hidden: false,
149
- saveable: true,
150
- translate: true,
151
- autofocus: false,
152
- width: "1/2",
153
- };
42
+ import type { KirbyQueryRequest, KirbyQueryResponse } from "kirby-types";
154
43
 
155
- // Type-specific field props
156
- const textField: KirbyTextFieldProps = {
157
- ...field,
158
- type: "text",
159
- counter: true,
160
- font: "sans-serif",
161
- spellcheck: false,
162
- maxlength: 100,
163
- };
164
-
165
- // Fieldset (block type definition from Fieldset->toArray())
166
- const fieldset: KirbyFieldsetProps = {
167
- disabled: false,
168
- editable: true,
169
- icon: "text",
170
- label: null,
171
- name: "Heading",
172
- preview: "fields",
173
- tabs: {
174
- content: {
175
- name: "content",
176
- label: "Content",
177
- fields: { text: field },
44
+ // Define your query with full type safety
45
+ const request: KirbyQueryRequest = {
46
+ query: "site",
47
+ select: {
48
+ title: true,
49
+ children: {
50
+ query: "site.children",
51
+ select: ["id", "title", "isListed"],
178
52
  },
179
53
  },
180
- translate: true,
181
- type: "heading",
182
- unset: false,
183
- wysiwyg: false,
184
54
  };
185
55
 
186
- // Option (from Option->render())
187
- const option: KirbyOption = {
188
- disabled: false,
189
- icon: "page",
190
- info: null,
191
- text: "Draft",
192
- value: "draft",
193
- };
56
+ // Type the response
57
+ interface SiteData {
58
+ title: string;
59
+ children: { id: string; title: string; isListed: boolean }[];
60
+ }
61
+
62
+ type Response = KirbyQueryResponse<SiteData>;
194
63
  ```
195
64
 
196
- ### Blocks
65
+ ### Typing Blocks with Content
197
66
 
198
67
  ```ts
199
- import type { KirbyBlock, KirbyDefaultBlockType } from "kirby-types";
68
+ import type { KirbyBlock } from "kirby-types";
200
69
 
201
- // Using a default block type
70
+ // Default block types are fully typed
202
71
  const textBlock: KirbyBlock<"text"> = {
203
72
  id: "abc123",
204
73
  type: "text",
205
74
  isHidden: false,
206
- content: { text: "Hello world" },
75
+ content: { text: "<p>Hello world</p>" },
207
76
  };
208
77
 
209
- // Using a custom block type
78
+ // Custom blocks with your own content structure
210
79
  interface HeroContent {
211
80
  title: string;
212
81
  image: string;
@@ -225,13 +94,13 @@ const heroBlock: KirbyBlock<"hero", HeroContent> = {
225
94
  };
226
95
  ```
227
96
 
228
- ### Layouts
97
+ ### Typing Layouts
229
98
 
230
99
  ```ts
231
- import type { KirbyLayout, KirbyLayoutColumn } from "kirby-types";
100
+ import type { KirbyBlock, KirbyLayout } from "kirby-types";
232
101
 
233
102
  const layout: KirbyLayout = {
234
- id: "layout-xyz789",
103
+ id: "layout-1",
235
104
  attrs: { class: "highlight" },
236
105
  columns: [
237
106
  { id: "col-1", width: "1/3", blocks: [] },
@@ -240,66 +109,116 @@ const layout: KirbyLayout = {
240
109
  };
241
110
  ```
242
111
 
243
- ### KQL Queries
112
+ ## Common Patterns
113
+
114
+ ### Pattern 1: Full Page Response with Blocks and Layouts
244
115
 
245
116
  ```ts
246
- import type {
247
- KirbyQuery,
248
- KirbyQueryRequest,
249
- KirbyQueryResponse,
250
- } from "kirby-types";
117
+ import type { KirbyBlock, KirbyLayout, PanelModelData } from "kirby-types";
118
+
119
+ // Define custom block types alongside defaults
120
+ interface CallToActionContent {
121
+ text: string;
122
+ url: string;
123
+ style: "primary" | "secondary";
124
+ }
251
125
 
252
- // KQL request with pagination
126
+ type CustomBlock =
127
+ | KirbyBlock<"text">
128
+ | KirbyBlock<"heading">
129
+ | KirbyBlock<"image">
130
+ | KirbyBlock<"cta", CallToActionContent>;
131
+
132
+ interface BlogPostContent {
133
+ date: string;
134
+ author: string;
135
+ blocks: CustomBlock[];
136
+ layout: KirbyLayout[];
137
+ }
138
+
139
+ type BlogPostPage = PanelModelData<BlogPostContent>;
140
+ ```
141
+
142
+ ### Pattern 2: KQL Queries with Pagination
143
+
144
+ ```ts
145
+ import type { KirbyQueryRequest, KirbyQueryResponse } from "kirby-types";
146
+
147
+ // Define request
253
148
  const request: KirbyQueryRequest = {
254
149
  query: 'page("blog").children.listed',
255
150
  select: {
256
151
  title: "page.title",
257
152
  date: "page.date.toDate",
153
+ excerpt: "page.text.toBlocks.excerpt(200)",
258
154
  },
259
- pagination: { limit: 10 },
155
+ pagination: { limit: 10, page: 1 },
260
156
  };
261
157
 
262
- // Typed response
263
- interface BlogPost {
158
+ // Type the response data
159
+ interface BlogPostSummary {
264
160
  title: string;
265
161
  date: string;
162
+ excerpt: string;
266
163
  }
267
164
 
268
- const response: KirbyQueryResponse<BlogPost[], true> = {
269
- code: 200,
270
- status: "ok",
271
- result: {
272
- data: [{ title: "Post 1", date: "2024-01-01" }],
273
- pagination: { page: 1, pages: 5, offset: 0, limit: 10, total: 50 },
274
- },
275
- };
165
+ // With pagination (second generic = true)
166
+ type PaginatedResponse = KirbyQueryResponse<BlogPostSummary[], true>;
167
+
168
+ // Response shape:
169
+ // {
170
+ // code: 200,
171
+ // status: "ok",
172
+ // result: {
173
+ // data: BlogPostSummary[],
174
+ // pagination: { page, pages, offset, limit, total }
175
+ // }
176
+ // }
276
177
  ```
277
178
 
278
- ### Query Parsing
179
+ ## Panel Types
279
180
 
280
- Parse query strings into structured objects at the type level:
181
+ For Panel plugin development, type the global `window.panel` object:
281
182
 
282
183
  ```ts
283
- import type { ParseKirbyQuery } from "kirby-types";
284
-
285
- type Parsed = ParseKirbyQuery<'page.children.filterBy("status", "published")'>;
286
- // Result: {
287
- // model: "page";
288
- // chain: [
289
- // { type: "property"; name: "children" },
290
- // { type: "method"; name: "filterBy"; params: '"status", "published"' }
291
- // ]
292
- // }
184
+ import type { Panel } from "kirby-types";
185
+
186
+ declare global {
187
+ interface Window {
188
+ panel: Panel;
189
+ }
190
+ }
191
+ ```
192
+
193
+ Common Panel operations:
194
+
195
+ ```ts
196
+ // Notifications
197
+ window.panel.notification.success("Changes saved");
198
+ window.panel.notification.error("Something went wrong");
199
+
200
+ // Theme
201
+ window.panel.theme.set("dark");
202
+
203
+ // Navigation
204
+ await window.panel.view.open("/pages/blog");
205
+ await window.panel.dialog.open("/dialogs/pages/create");
206
+
207
+ // API calls
208
+ const page = await window.panel.api.pages.read("blog");
209
+ await window.panel.api.pages.update("blog", { title: "New Title" });
210
+
211
+ // Content state
212
+ const currentContent = panel.content.version("changes");
293
213
  ```
294
214
 
295
- ### Writer Extensions
215
+ ## Advanced: Writer Extensions
296
216
 
297
- For ProseMirror-based Writer extensions (requires optional ProseMirror peer dependencies):
217
+ For ProseMirror-based Writer extensions (requires optional peer dependencies):
298
218
 
299
219
  ```ts
300
220
  import type { WriterMarkExtension } from "kirby-types";
301
221
 
302
- // Define a custom mark extension
303
222
  const highlight: WriterMarkExtension = {
304
223
  button: {
305
224
  icon: "highlight",
@@ -318,108 +237,93 @@ const highlight: WriterMarkExtension = {
318
237
  };
319
238
  ```
320
239
 
240
+ <details>
241
+ <summary>Required peer dependencies for Writer types</summary>
242
+
243
+ ```bash
244
+ pnpm add -D prosemirror-commands prosemirror-inputrules prosemirror-model prosemirror-schema-list prosemirror-state prosemirror-view
245
+ ```
246
+
247
+ </details>
248
+
321
249
  ## API Reference
322
250
 
323
- ### Panel
324
-
325
- | Type | Description |
326
- | -------------------------------------------- | ----------------------------------- |
327
- | [`Panel`](./src/panel/index.d.ts) | Main Panel interface |
328
- | [`PanelApi`](./src/panel/api.d.ts) | API client methods |
329
- | [`PanelState`](./src/panel/base.d.ts) | Base state interface |
330
- | [`PanelFeature`](./src/panel/base.d.ts) | Feature with loading states |
331
- | [`PanelModal`](./src/panel/base.d.ts) | Modal (dialog/drawer) interface |
332
- | [`PanelHelpers`](./src/panel/helpers.d.ts) | Utility functions |
333
- | [`PanelLibrary`](./src/panel/libraries.d.ts) | Libraries (colors, dayjs, autosize) |
334
-
335
- ### Writer
336
-
337
- | Type | Description |
338
- | --------------------------------------------------- | ---------------------------------- |
339
- | [`WriterEditor`](./src/panel/writer.d.ts) | Main editor instance |
340
- | [`WriterExtensions`](./src/panel/writer.d.ts) | Extensions manager |
341
- | [`WriterExtension`](./src/panel/writer.d.ts) | Generic extension interface |
342
- | [`WriterMarkExtension`](./src/panel/writer.d.ts) | Mark extension interface |
343
- | [`WriterNodeExtension`](./src/panel/writer.d.ts) | Node extension interface |
344
- | [`WriterMarkContext`](./src/panel/writer.d.ts) | Context for mark extensions |
345
- | [`WriterNodeContext`](./src/panel/writer.d.ts) | Context for node extensions |
346
- | [`WriterExtensionContext`](./src/panel/writer.d.ts) | Context for generic extensions |
347
- | [`WriterUtils`](./src/panel/writer.d.ts) | ProseMirror commands and utilities |
348
-
349
- ### API
350
-
351
- | Type | Description |
352
- | --------------------------------------- | ------------------------------------- |
353
- | [`KirbyApiResponse<T>`](./src/api.d.ts) | Standard Kirby API response structure |
354
-
355
- ### Blueprints
356
-
357
- | Type | Description |
358
- | -------------------------------------------------- | ---------------------------------------------- |
359
- | [`KirbyAnyFieldProps`](./src/blueprint.d.ts) | Union of all field prop types |
360
- | [`KirbyBlocksFieldProps`](./src/blueprint.d.ts) | Blocks field props with fieldsets |
361
- | [`KirbyColorFieldProps`](./src/blueprint.d.ts) | Color picker field props |
362
- | [`KirbyDateFieldProps`](./src/blueprint.d.ts) | Date and time field props |
363
- | [`KirbyFieldProps`](./src/blueprint.d.ts) | Base field props from `Field->toArray()` |
364
- | [`KirbyFieldsetProps`](./src/blueprint.d.ts) | Fieldset from `Fieldset->toArray()` |
365
- | [`KirbyFilesFieldProps`](./src/blueprint.d.ts) | Files/pages/users picker field props |
366
- | [`KirbyLayoutFieldProps`](./src/blueprint.d.ts) | Layout field props with fieldsets and settings |
367
- | [`KirbyLinkFieldProps`](./src/blueprint.d.ts) | Link field props |
368
- | [`KirbyNumberFieldProps`](./src/blueprint.d.ts) | Number field props |
369
- | [`KirbyObjectFieldProps`](./src/blueprint.d.ts) | Object field props with nested fields |
370
- | [`KirbyOption`](./src/blueprint.d.ts) | Option from `Option->render()` |
371
- | [`KirbyOptionsFieldProps`](./src/blueprint.d.ts) | Select/radio/checkboxes/multiselect/toggles |
372
- | [`KirbyRangeFieldProps`](./src/blueprint.d.ts) | Range slider field props |
373
- | [`KirbyStructureFieldProps`](./src/blueprint.d.ts) | Structure field props with nested fields |
374
- | [`KirbyTagsFieldProps`](./src/blueprint.d.ts) | Tags field props |
375
- | [`KirbyTextFieldProps`](./src/blueprint.d.ts) | Text/textarea field props |
376
- | [`KirbyToggleFieldProps`](./src/blueprint.d.ts) | Toggle (boolean) field props |
377
- | [`KirbyWriterFieldProps`](./src/blueprint.d.ts) | Writer (rich text) field props |
378
-
379
- ### Blocks
380
-
381
- | Type | Description |
382
- | -------------------------------------------- | --------------------------------- |
383
- | [`KirbyBlock<T, U>`](./src/blocks.d.ts) | Block with type and content |
384
- | [`KirbyCodeLanguage`](./src/blocks.d.ts) | Valid code block languages |
385
- | [`KirbyDefaultBlocks`](./src/blocks.d.ts) | Default block content types |
386
- | [`KirbyDefaultBlockType`](./src/blocks.d.ts) | Union of default block type names |
387
-
388
- ### Layouts
389
-
390
- | Type | Description |
391
- | --------------------------------------------- | ---------------------------- |
392
- | [`KirbyLayout`](./src/layout.d.ts) | Layout row with columns |
393
- | [`KirbyLayoutColumn`](./src/layout.d.ts) | Column with width and blocks |
394
- | [`KirbyLayoutColumnWidth`](./src/layout.d.ts) | Valid column width fractions |
395
-
396
- ### KQL
251
+ ### Content Types (Most Used)
252
+
253
+ | Type | Description |
254
+ | -------------------------------------------- | ---------------------------------- |
255
+ | [`KirbyApiResponse<T>`](./src/api.d.ts) | Standard API response wrapper |
256
+ | [`KirbyBlock<T, U>`](./src/blocks.d.ts) | Block with type and content |
257
+ | [`KirbyLayout`](./src/layout.d.ts) | Layout row with columns |
258
+ | [`KirbyLayoutColumn`](./src/layout.d.ts) | Column with width and blocks |
259
+ | [`KirbyDefaultBlocks`](./src/blocks.d.ts) | Map of default block content types |
260
+ | [`KirbyDefaultBlockType`](./src/blocks.d.ts) | Union of default block type names |
261
+
262
+ ### KQL Types
397
263
 
398
264
  | Type | Description |
399
265
  | -------------------------------------------- | ------------------------------------- |
400
- | [`KirbyQuerySchema`](./src/kql.d.ts) | KQL query schema structure |
401
266
  | [`KirbyQueryRequest`](./src/kql.d.ts) | KQL request with pagination |
402
267
  | [`KirbyQueryResponse<T, P>`](./src/kql.d.ts) | KQL response with optional pagination |
268
+ | [`KirbyQuerySchema`](./src/kql.d.ts) | KQL query schema structure |
269
+ | [`KirbyQuery<M>`](./src/query.d.ts) | Valid KQL query string |
270
+ | [`ParseKirbyQuery<T>`](./src/query.d.ts) | Parse query string to structured type |
403
271
 
404
- ### Query
272
+ ### Panel Types
405
273
 
406
- | Type | Description |
407
- | ---------------------------------------- | ------------------------------------- |
408
- | [`KirbyQuery<M>`](./src/query.d.ts) | Valid KQL query string |
409
- | [`KirbyQueryModel<M>`](./src/query.d.ts) | Supported query models |
410
- | [`KirbyQueryChain<M>`](./src/query.d.ts) | Query chain patterns |
411
- | [`ParseKirbyQuery<T>`](./src/query.d.ts) | Parse query string to structured type |
274
+ | Type | Description |
275
+ | ------------------------------------------ | ------------------------------- |
276
+ | [`Panel`](./src/panel/index.d.ts) | Main Panel interface |
277
+ | [`PanelApi`](./src/panel/api.d.ts) | API client methods |
278
+ | [`PanelState`](./src/panel/base.d.ts) | Base state interface |
279
+ | [`PanelFeature`](./src/panel/base.d.ts) | Feature with loading states |
280
+ | [`PanelModal`](./src/panel/base.d.ts) | Modal (dialog/drawer) interface |
281
+ | [`PanelHelpers`](./src/panel/helpers.d.ts) | Utility functions |
282
+
283
+ ### Blueprint Types
284
+
285
+ | Type | Description |
286
+ | -------------------------------------------------- | ---------------------------------------- |
287
+ | [`KirbyFieldProps`](./src/blueprint.d.ts) | Base field props from `Field->toArray()` |
288
+ | [`KirbyFieldsetProps`](./src/blueprint.d.ts) | Fieldset from `Fieldset->toArray()` |
289
+ | [`KirbyBlocksFieldProps`](./src/blueprint.d.ts) | Blocks field props with fieldsets |
290
+ | [`KirbyStructureFieldProps`](./src/blueprint.d.ts) | Structure field props with nested fields |
291
+ | [`KirbyLayoutFieldProps`](./src/blueprint.d.ts) | Layout field props with settings |
292
+ | [`KirbyAnyFieldProps`](./src/blueprint.d.ts) | Union of all field prop types |
293
+
294
+ ### Writer Types
295
+
296
+ | Type | Description |
297
+ | ------------------------------------------------ | ---------------------------------- |
298
+ | [`WriterEditor`](./src/panel/writer.d.ts) | Main editor instance |
299
+ | [`WriterMarkExtension`](./src/panel/writer.d.ts) | Mark extension interface |
300
+ | [`WriterNodeExtension`](./src/panel/writer.d.ts) | Node extension interface |
301
+ | [`WriterUtils`](./src/panel/writer.d.ts) | ProseMirror commands and utilities |
302
+
303
+ <details>
304
+ <summary>View all Blueprint field types</summary>
305
+
306
+ | Type | Description |
307
+ | ------------------------------------------------- | ------------------------------- |
308
+ | [`KirbyTextFieldProps`](./src/blueprint.d.ts) | Text field props |
309
+ | [`KirbyTextareaFieldProps`](./src/blueprint.d.ts) | Textarea field props |
310
+ | [`KirbyNumberFieldProps`](./src/blueprint.d.ts) | Number field props |
311
+ | [`KirbyDateFieldProps`](./src/blueprint.d.ts) | Date and time field props |
312
+ | [`KirbyFilesFieldProps`](./src/blueprint.d.ts) | Files/pages/users picker props |
313
+ | [`KirbyOptionsFieldProps`](./src/blueprint.d.ts) | Select/radio/checkboxes/toggles |
314
+ | [`KirbyToggleFieldProps`](./src/blueprint.d.ts) | Toggle (boolean) field props |
315
+ | [`KirbyColorFieldProps`](./src/blueprint.d.ts) | Color picker field props |
316
+ | [`KirbyRangeFieldProps`](./src/blueprint.d.ts) | Range slider field props |
317
+ | [`KirbyTagsFieldProps`](./src/blueprint.d.ts) | Tags field props |
318
+ | [`KirbyLinkFieldProps`](./src/blueprint.d.ts) | Link field props |
319
+ | [`KirbyObjectFieldProps`](./src/blueprint.d.ts) | Object field props |
320
+ | [`KirbyWriterFieldProps`](./src/blueprint.d.ts) | Writer (rich text) field props |
321
+
322
+ </details>
412
323
 
413
324
  ## Optional Dependencies
414
325
 
415
- The Panel types include Writer types that require ProseMirror packages. These are optional peer dependencies:
416
-
417
- ```bash
418
- # Only needed if using Writer extension types
419
- pnpm add -D prosemirror-commands prosemirror-inputrules prosemirror-model prosemirror-schema-list prosemirror-state
420
- ```
421
-
422
- Vue is also an optional peer dependency for Panel types:
326
+ Vue is an optional peer dependency for Panel types:
423
327
 
424
328
  ```bash
425
329
  pnpm add -D vue@^2.7.0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kirby-types",
3
3
  "type": "module",
4
- "version": "1.4.5",
4
+ "version": "1.4.6",
5
5
  "packageManager": "pnpm@10.27.0",
6
6
  "description": "TypeScript types for Kirby Panel plugins and headless CMS usage",
7
7
  "author": "Johann Schopplich <hello@johannschopplich.com>",
@@ -301,6 +301,16 @@ export interface KirbyFilesFieldProps extends KirbyFieldProps {
301
301
  value?: KirbyPickerItem[];
302
302
  }
303
303
 
304
+ /**
305
+ * Color option for the color field.
306
+ */
307
+ export interface KirbyColorOption {
308
+ /** Color value (hex, rgb, or hsl) */
309
+ value: string;
310
+ /** Optional display text/label */
311
+ text?: string;
312
+ }
313
+
304
314
  /**
305
315
  * Props for color fields.
306
316
  *
@@ -319,16 +329,6 @@ export interface KirbyColorFieldProps extends KirbyFieldProps {
319
329
  value?: string;
320
330
  }
321
331
 
322
- /**
323
- * Color option for the color field.
324
- */
325
- export interface KirbyColorOption {
326
- /** Color value (hex, rgb, or hsl) */
327
- value: string;
328
- /** Optional display text/label */
329
- text?: string;
330
- }
331
-
332
332
  /**
333
333
  * Props for range fields (slider input).
334
334
  *
@@ -397,6 +397,28 @@ export interface KirbyLinkFieldProps extends KirbyFieldProps {
397
397
  value?: string;
398
398
  }
399
399
 
400
+ /**
401
+ * Column definition for structure field table display.
402
+ */
403
+ export interface KirbyStructureColumn {
404
+ /** Column label */
405
+ label?: string;
406
+ /** Column width */
407
+ width?: string;
408
+ /** Field type for display */
409
+ type?: string;
410
+ /** Whether to show mobile */
411
+ mobile?: boolean;
412
+ /** Text alignment */
413
+ align?: "left" | "center" | "right";
414
+ /** Value template */
415
+ value?: string;
416
+ /** Before text */
417
+ before?: string;
418
+ /** After text */
419
+ after?: string;
420
+ }
421
+
400
422
  /**
401
423
  * Props for structure fields.
402
424
  *
@@ -429,28 +451,6 @@ export interface KirbyStructureFieldProps extends KirbyFieldProps {
429
451
  value?: Record<string, any>[];
430
452
  }
431
453
 
432
- /**
433
- * Column definition for structure field table display.
434
- */
435
- export interface KirbyStructureColumn {
436
- /** Column label */
437
- label?: string;
438
- /** Column width */
439
- width?: string;
440
- /** Field type for display */
441
- type?: string;
442
- /** Whether to show mobile */
443
- mobile?: boolean;
444
- /** Text alignment */
445
- align?: "left" | "center" | "right";
446
- /** Value template */
447
- value?: string;
448
- /** Before text */
449
- before?: string;
450
- /** After text */
451
- after?: string;
452
- }
453
-
454
454
  /**
455
455
  * Props for object fields.
456
456
  *
@@ -625,18 +625,6 @@ export interface KirbyBlockValue {
625
625
  type: string;
626
626
  }
627
627
 
628
- /**
629
- * Layout value as stored in content.
630
- */
631
- export interface KirbyLayoutValue {
632
- /** Layout attributes */
633
- attrs: Record<string, any> | any[];
634
- /** Layout columns */
635
- columns: KirbyLayoutColumnValue[];
636
- /** Unique layout identifier */
637
- id: string;
638
- }
639
-
640
628
  /**
641
629
  * Layout column value as stored in content.
642
630
  */
@@ -649,6 +637,18 @@ export interface KirbyLayoutColumnValue {
649
637
  width: string;
650
638
  }
651
639
 
640
+ /**
641
+ * Layout value as stored in content.
642
+ */
643
+ export interface KirbyLayoutValue {
644
+ /** Layout attributes */
645
+ attrs: Record<string, any> | any[];
646
+ /** Layout columns */
647
+ columns: KirbyLayoutColumnValue[];
648
+ /** Unique layout identifier */
649
+ id: string;
650
+ }
651
+
652
652
  // -----------------------------------------------------------------------------
653
653
  // Fieldset (Block Type Definition)
654
654
  // -----------------------------------------------------------------------------
@@ -68,7 +68,7 @@ export interface PanelState<TDefaults extends object = Record<string, any>> {
68
68
  * Validates that the state is a plain object.
69
69
  * @throws Error if state is not an object
70
70
  */
71
- validateState: (state: any) => boolean;
71
+ validateState: (state: unknown) => boolean;
72
72
  }
73
73
 
74
74
  // -----------------------------------------------------------------------------
@@ -86,7 +86,7 @@ export interface PanelStateBase {
86
86
  reset: () => Record<string, any>;
87
87
  set: (state: Record<string, any>) => Record<string, any>;
88
88
  state: () => Record<string, any>;
89
- validateState: (state: any) => boolean;
89
+ validateState: (state: unknown) => boolean;
90
90
  }
91
91
 
92
92
  /**
@@ -39,12 +39,12 @@ export interface PanelTimer {
39
39
 
40
40
  /**
41
41
  * Starts the timer with a callback.
42
- * Stops any previous timer first.
42
+ * Stops any previous timer first. Does nothing if timeout is falsy.
43
43
  *
44
- * @param timeout - Delay in milliseconds
44
+ * @param timeout - Delay in milliseconds, or falsy to skip
45
45
  * @param callback - Function to call after timeout
46
46
  */
47
- start: (timeout: number | null, callback: () => void) => void;
47
+ start: (timeout: number | false | null, callback: () => void) => void;
48
48
 
49
49
  /**
50
50
  * Stops the timer and clears the interval.
@@ -345,8 +345,8 @@ export interface PanelNotificationDefaults {
345
345
  message: string | null;
346
346
  /** Visual theme */
347
347
  theme: NotificationTheme | null;
348
- /** Auto-close timeout in ms */
349
- timeout: number | null;
348
+ /** Auto-close timeout in ms, or `false` to disable auto-close */
349
+ timeout: number | false | null;
350
350
  /** Notification type */
351
351
  type: NotificationType | null;
352
352
  }
@@ -365,8 +365,8 @@ export interface PanelNotificationOptions {
365
365
  message?: string;
366
366
  /** Visual theme */
367
367
  theme?: NotificationTheme;
368
- /** Auto-close timeout in ms (default: 4000 for non-errors) */
369
- timeout?: number;
368
+ /** Auto-close timeout in ms (default: 4000 for non-errors), or `false` to disable auto-close */
369
+ timeout?: number | false;
370
370
  /** Notification type */
371
371
  type?: NotificationType;
372
372
  }
@@ -405,8 +405,8 @@ export interface PanelNotification extends PanelState<PanelNotificationDefaults>
405
405
  message: string | null;
406
406
  /** Visual theme */
407
407
  theme: NotificationTheme | null;
408
- /** Auto-close timeout in ms */
409
- timeout: number | null;
408
+ /** Auto-close timeout in ms, or `false` to disable auto-close */
409
+ timeout: number | false | null;
410
410
  /** Notification type */
411
411
  type: NotificationType | null;
412
412
 
@@ -270,7 +270,7 @@ export interface PanelHelpersObject {
270
270
  * @param value - Value to check
271
271
  * @returns True if empty
272
272
  */
273
- isEmpty: (value: any) => boolean;
273
+ isEmpty: (value: unknown) => boolean;
274
274
 
275
275
  /**
276
276
  * Checks if input is a plain object (not array, null, etc.).
@@ -278,7 +278,7 @@ export interface PanelHelpersObject {
278
278
  * @param input - Value to check
279
279
  * @returns True if plain object
280
280
  */
281
- isObject: (input: any) => input is Record<string, any>;
281
+ isObject: (input: unknown) => input is Record<string, unknown>;
282
282
 
283
283
  /**
284
284
  * Counts keys in an object.
@@ -304,7 +304,7 @@ export interface PanelHelpersObject {
304
304
  * @param b - Second object
305
305
  * @returns True if identical
306
306
  */
307
- same: (a: any, b: any) => boolean;
307
+ same: (a: unknown, b: unknown) => boolean;
308
308
 
309
309
  /**
310
310
  * Converts all object keys to lowercase.
package/src/query.d.ts CHANGED
@@ -126,6 +126,52 @@ export type KirbyQuery<CustomModel extends string = never> =
126
126
  ? never
127
127
  : KirbyQueryChain<CustomModel>);
128
128
 
129
+ /**
130
+ * Recursively parses a chain of query segments separated by dots.
131
+ *
132
+ * @example
133
+ * ```ts
134
+ * type Chain = ParseQueryChain<"children.listed.first">;
135
+ * // Result: [
136
+ * // { type: "property"; name: "children" },
137
+ * // { type: "property"; name: "listed" },
138
+ * // { type: "property"; name: "first" }
139
+ * // ]
140
+ * ```
141
+ *
142
+ * @internal
143
+ */
144
+ type ParseQueryChain<T extends string> =
145
+ T extends `${infer First}.${infer Rest}`
146
+ ? [ParseQuerySegment<First>, ...ParseQueryChain<Rest>]
147
+ : [ParseQuerySegment<T>];
148
+
149
+ /**
150
+ * Parses a single query segment to determine if it's a property access or method call.
151
+ *
152
+ * @example
153
+ * ```ts
154
+ * type Property = ParseQuerySegment<"children">;
155
+ * // Result: { type: "property"; name: "children" }
156
+ *
157
+ * type Method = ParseQuerySegment<'filterBy("status", "published")'>;
158
+ * // Result: { type: "method"; name: "filterBy"; params: '"status", "published"' }
159
+ * ```
160
+ *
161
+ * @internal
162
+ */
163
+ type ParseQuerySegment<T extends string> =
164
+ T extends `${infer Name}(${infer Params})`
165
+ ? {
166
+ type: "method";
167
+ name: Name;
168
+ params: Params;
169
+ }
170
+ : {
171
+ type: "property";
172
+ name: T;
173
+ };
174
+
129
175
  /**
130
176
  * Parses a Kirby Query Language (KQL) string into a structured object.
131
177
  *
@@ -199,49 +245,3 @@ export type ParseKirbyQuery<T extends string, M extends string = never> =
199
245
  : never
200
246
  : never
201
247
  : never;
202
-
203
- /**
204
- * Recursively parses a chain of query segments separated by dots.
205
- *
206
- * @example
207
- * ```ts
208
- * type Chain = ParseQueryChain<"children.listed.first">;
209
- * // Result: [
210
- * // { type: "property"; name: "children" },
211
- * // { type: "property"; name: "listed" },
212
- * // { type: "property"; name: "first" }
213
- * // ]
214
- * ```
215
- *
216
- * @internal
217
- */
218
- type ParseQueryChain<T extends string> =
219
- T extends `${infer First}.${infer Rest}`
220
- ? [ParseQuerySegment<First>, ...ParseQueryChain<Rest>]
221
- : [ParseQuerySegment<T>];
222
-
223
- /**
224
- * Parses a single query segment to determine if it's a property access or method call.
225
- *
226
- * @example
227
- * ```ts
228
- * type Property = ParseQuerySegment<"children">;
229
- * // Result: { type: "property"; name: "children" }
230
- *
231
- * type Method = ParseQuerySegment<'filterBy("status", "published")'>;
232
- * // Result: { type: "method"; name: "filterBy"; params: '"status", "published"' }
233
- * ```
234
- *
235
- * @internal
236
- */
237
- type ParseQuerySegment<T extends string> =
238
- T extends `${infer Name}(${infer Params})`
239
- ? {
240
- type: "method";
241
- name: Name;
242
- params: Params;
243
- }
244
- : {
245
- type: "property";
246
- name: T;
247
- };