@setzkasten-cms/core 0.4.4 → 0.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.
@@ -88,6 +88,7 @@ var f = {
88
88
  });
89
89
  },
90
90
  array(itemField, options) {
91
+ const layout = options.layout ?? "list";
91
92
  return Object.freeze({
92
93
  type: "array",
93
94
  label: options.label,
@@ -96,7 +97,10 @@ var f = {
96
97
  itemField,
97
98
  minItems: options.minItems,
98
99
  maxItems: options.maxItems,
99
- itemLabel: options.itemLabel
100
+ itemLabel: options.itemLabel,
101
+ layout,
102
+ gridColumns: options.gridColumns ?? 3,
103
+ collapsible: options.collapsible ?? layout === "list"
100
104
  });
101
105
  },
102
106
  object(fields, options) {
@@ -109,6 +113,18 @@ var f = {
109
113
  collapsible: options.collapsible ?? false
110
114
  });
111
115
  },
116
+ date(options) {
117
+ return Object.freeze({
118
+ type: "date",
119
+ label: options.label,
120
+ description: options.description,
121
+ defaultValue: options.defaultValue ?? "",
122
+ required: options.required ?? false,
123
+ includeTime: options.includeTime ?? false,
124
+ min: options.min,
125
+ max: options.max
126
+ });
127
+ },
112
128
  color(options) {
113
129
  return Object.freeze({
114
130
  type: "color",
@@ -1,5 +1,5 @@
1
1
  /** Discriminator for all field types */
2
- type FieldType = 'text' | 'number' | 'boolean' | 'select' | 'icon' | 'image' | 'array' | 'object' | 'conditional' | 'color' | 'override';
2
+ type FieldType = 'text' | 'number' | 'boolean' | 'select' | 'icon' | 'image' | 'array' | 'object' | 'conditional' | 'color' | 'date' | 'override';
3
3
  /** Path to a field in a nested schema (e.g. ['items', 0, 'title']) */
4
4
  type FieldPath = ReadonlyArray<string | number>;
5
5
  /**
@@ -100,6 +100,8 @@ interface ImageFieldDef extends FieldDefinition<'image', ImageValue> {
100
100
  readonly maxSize?: string;
101
101
  readonly filenameStrategy: 'original' | 'slugified' | 'custom';
102
102
  }
103
+ /** Layout mode for array fields */
104
+ type ArrayLayout = 'list' | 'grid';
103
105
  interface ArrayFieldOptions {
104
106
  label: string;
105
107
  description?: string;
@@ -107,12 +109,21 @@ interface ArrayFieldOptions {
107
109
  minItems?: number;
108
110
  maxItems?: number;
109
111
  itemLabel?: (item: unknown, index: number) => string;
112
+ /** Display layout: 'list' (default, vertical) or 'grid' (cards) */
113
+ layout?: ArrayLayout;
114
+ /** Columns for grid layout (default: 3) */
115
+ gridColumns?: number;
116
+ /** Allow collapsing items (default: true for list, false for grid) */
117
+ collapsible?: boolean;
110
118
  }
111
119
  interface ArrayFieldDef<TItem extends FieldDefinition = FieldDefinition> extends FieldDefinition<'array', InferFieldValue<TItem>[]> {
112
120
  readonly itemField: TItem;
113
121
  readonly minItems?: number;
114
122
  readonly maxItems?: number;
115
123
  readonly itemLabel?: (item: unknown, index: number) => string;
124
+ readonly layout: ArrayLayout;
125
+ readonly gridColumns: number;
126
+ readonly collapsible: boolean;
116
127
  }
117
128
  interface ObjectFieldOptions {
118
129
  label: string;
@@ -125,6 +136,23 @@ interface ObjectFieldDef<TFields extends FieldRecord = FieldRecord> extends Fiel
125
136
  readonly fields: TFields;
126
137
  readonly collapsible: boolean;
127
138
  }
139
+ interface DateFieldOptions {
140
+ label: string;
141
+ description?: string;
142
+ defaultValue?: string;
143
+ required?: boolean;
144
+ /** Include time picker (default: false = date only) */
145
+ includeTime?: boolean;
146
+ /** Minimum date (ISO string, e.g. '2024-01-01') */
147
+ min?: string;
148
+ /** Maximum date (ISO string) */
149
+ max?: string;
150
+ }
151
+ interface DateFieldDef extends FieldDefinition<'date', string> {
152
+ readonly includeTime: boolean;
153
+ readonly min?: string;
154
+ readonly max?: string;
155
+ }
128
156
  interface ColorFieldOptions {
129
157
  label: string;
130
158
  description?: string;
@@ -150,7 +178,7 @@ type InferSchemaValues<S extends FieldRecord> = {
150
178
  [K in keyof S]: InferFieldValue<S[K]>;
151
179
  };
152
180
  /** Union of all concrete field definitions */
153
- type AnyFieldDef = TextFieldDef | NumberFieldDef | BooleanFieldDef | SelectFieldDef | IconFieldDef | ImageFieldDef | ArrayFieldDef | ObjectFieldDef | ColorFieldDef | OverrideFieldDef;
181
+ type AnyFieldDef = TextFieldDef | NumberFieldDef | BooleanFieldDef | SelectFieldDef | IconFieldDef | ImageFieldDef | ArrayFieldDef | ObjectFieldDef | DateFieldDef | ColorFieldDef | OverrideFieldDef;
154
182
 
155
183
  interface SectionDefinition<TFields extends FieldRecord = FieldRecord> {
156
184
  readonly label: string;
@@ -206,4 +234,4 @@ interface SetzKastenConfig {
206
234
  }
207
235
  declare function defineConfig(config: SetzKastenConfig): SetzKastenConfig;
208
236
 
209
- export { type ArrayFieldOptions as A, type BooleanFieldOptions as B, type ColorFieldOptions as C, type ThemeConfig as D, defineCollection as E, type FieldDefinition as F, defineConfig as G, defineSection as H, type IconFieldOptions as I, type NumberFieldOptions as N, type ObjectFieldOptions as O, type ProductDefinition as P, type SelectFieldOptions as S, type TextFieldOptions as T, type TextFieldDef as a, type NumberFieldDef as b, type BooleanFieldDef as c, type SelectFieldDef as d, type IconFieldDef as e, type ImageFieldOptions as f, type ImageFieldDef as g, type ArrayFieldDef as h, type FieldRecord as i, type ObjectFieldDef as j, type ColorFieldDef as k, type OverrideFieldOptions as l, type OverrideFieldDef as m, type FieldPath as n, type AnyFieldDef as o, type AuthConfig as p, type CollectionDefinition as q, type FieldType as r, type IconsConfig as s, type ImageValue as t, type InferFieldValue as u, type InferSchemaValues as v, type SectionDefinition as w, type SelectOption as x, type SetzKastenConfig as y, type StorageConfig as z };
237
+ export { type ArrayFieldOptions as A, type BooleanFieldOptions as B, type ColorFieldOptions as C, type DateFieldOptions as D, type StorageConfig as E, type FieldDefinition as F, type ThemeConfig as G, defineCollection as H, type IconFieldOptions as I, defineConfig as J, defineSection as K, type NumberFieldOptions as N, type ObjectFieldOptions as O, type ProductDefinition as P, type SelectFieldOptions as S, type TextFieldOptions as T, type TextFieldDef as a, type NumberFieldDef as b, type BooleanFieldDef as c, type SelectFieldDef as d, type IconFieldDef as e, type ImageFieldOptions as f, type ImageFieldDef as g, type ArrayFieldDef as h, type FieldRecord as i, type ObjectFieldDef as j, type DateFieldDef as k, type ColorFieldDef as l, type OverrideFieldOptions as m, type OverrideFieldDef as n, type FieldPath as o, type AnyFieldDef as p, type AuthConfig as q, type CollectionDefinition as r, type FieldType as s, type IconsConfig as t, type ImageValue as u, type InferFieldValue as v, type InferSchemaValues as w, type SectionDefinition as x, type SelectOption as y, type SetzKastenConfig as z };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { T as TextFieldOptions, a as TextFieldDef, N as NumberFieldOptions, b as NumberFieldDef, B as BooleanFieldOptions, c as BooleanFieldDef, S as SelectFieldOptions, d as SelectFieldDef, I as IconFieldOptions, e as IconFieldDef, f as ImageFieldOptions, g as ImageFieldDef, F as FieldDefinition, A as ArrayFieldOptions, h as ArrayFieldDef, i as FieldRecord, O as ObjectFieldOptions, j as ObjectFieldDef, C as ColorFieldOptions, k as ColorFieldDef, l as OverrideFieldOptions, m as OverrideFieldDef, n as FieldPath } from './define-config-bJ65Zaui.js';
2
- export { o as AnyFieldDef, p as AuthConfig, q as CollectionDefinition, r as FieldType, s as IconsConfig, t as ImageValue, u as InferFieldValue, v as InferSchemaValues, P as ProductDefinition, w as SectionDefinition, x as SelectOption, y as SetzKastenConfig, z as StorageConfig, D as ThemeConfig, E as defineCollection, G as defineConfig, H as defineSection } from './define-config-bJ65Zaui.js';
1
+ import { T as TextFieldOptions, a as TextFieldDef, N as NumberFieldOptions, b as NumberFieldDef, B as BooleanFieldOptions, c as BooleanFieldDef, S as SelectFieldOptions, d as SelectFieldDef, I as IconFieldOptions, e as IconFieldDef, f as ImageFieldOptions, g as ImageFieldDef, F as FieldDefinition, A as ArrayFieldOptions, h as ArrayFieldDef, i as FieldRecord, O as ObjectFieldOptions, j as ObjectFieldDef, D as DateFieldOptions, k as DateFieldDef, C as ColorFieldOptions, l as ColorFieldDef, m as OverrideFieldOptions, n as OverrideFieldDef, o as FieldPath } from './define-config-B8VZW6Xa.js';
2
+ export { p as AnyFieldDef, q as AuthConfig, r as CollectionDefinition, s as FieldType, t as IconsConfig, u as ImageValue, v as InferFieldValue, w as InferSchemaValues, P as ProductDefinition, x as SectionDefinition, y as SelectOption, z as SetzKastenConfig, E as StorageConfig, G as ThemeConfig, H as defineCollection, J as defineConfig, K as defineSection } from './define-config-B8VZW6Xa.js';
3
3
  import { z } from 'zod';
4
4
 
5
5
  /**
@@ -18,6 +18,7 @@ declare const f: {
18
18
  readonly image: (options: ImageFieldOptions) => ImageFieldDef;
19
19
  readonly array: <TItem extends FieldDefinition>(itemField: TItem, options: ArrayFieldOptions) => ArrayFieldDef<TItem>;
20
20
  readonly object: <TFields extends FieldRecord>(fields: TFields, options: ObjectFieldOptions) => ObjectFieldDef<TFields>;
21
+ readonly date: (options: DateFieldOptions) => DateFieldDef;
21
22
  readonly color: (options: ColorFieldOptions) => ColorFieldDef;
22
23
  /**
23
24
  * Override field – wraps a set of fields with an "active" checkbox.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  defineConfig,
4
4
  defineSection,
5
5
  f
6
- } from "./chunk-IL2PWN4R.js";
6
+ } from "./chunk-XIOKON7Y.js";
7
7
 
8
8
  // src/validation/schema-to-zod.ts
9
9
  import { z } from "zod";
@@ -25,6 +25,8 @@ function fieldToZod(field) {
25
25
  return arrayToZod(field);
26
26
  case "object":
27
27
  return objectToZod(field);
28
+ case "date":
29
+ return dateToZod(field);
28
30
  case "color":
29
31
  return z.string().regex(/^#[0-9a-fA-F]{6}$/, "Invalid hex color");
30
32
  case "override":
@@ -56,6 +58,13 @@ function numberToZod(field) {
56
58
  }
57
59
  return schema;
58
60
  }
61
+ function dateToZod(field) {
62
+ let schema = z.string();
63
+ if (field.required) {
64
+ schema = schema.min(1, `${field.label} ist erforderlich`);
65
+ }
66
+ return schema;
67
+ }
59
68
  function selectToZod(field) {
60
69
  const values = field.options.map((o) => o.value);
61
70
  if (values.length === 0) return z.string();
package/dist/testing.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { y as SetzKastenConfig } from './define-config-bJ65Zaui.js';
1
+ import { z as SetzKastenConfig } from './define-config-B8VZW6Xa.js';
2
2
 
3
3
  /**
4
4
  * @setzkasten-cms/core/testing – Test utilities for other packages
package/dist/testing.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  defineConfig,
3
3
  defineSection,
4
4
  f
5
- } from "./chunk-IL2PWN4R.js";
5
+ } from "./chunk-XIOKON7Y.js";
6
6
 
7
7
  // src/testing/index.ts
8
8
  function createTestConfig() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@setzkasten-cms/core",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "Schema-Engine, Feldtypen und Validierung für Setzkasten CMS",
5
5
  "type": "module",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -5,6 +5,8 @@ import type {
5
5
  BooleanFieldOptions,
6
6
  ColorFieldDef,
7
7
  ColorFieldOptions,
8
+ DateFieldDef,
9
+ DateFieldOptions,
8
10
  FieldDefinition,
9
11
  FieldRecord,
10
12
  IconFieldDef,
@@ -108,6 +110,7 @@ export const f = {
108
110
  itemField: TItem,
109
111
  options: ArrayFieldOptions,
110
112
  ): ArrayFieldDef<TItem> {
113
+ const layout = options.layout ?? 'list'
111
114
  return Object.freeze({
112
115
  type: 'array' as const,
113
116
  label: options.label,
@@ -117,6 +120,9 @@ export const f = {
117
120
  minItems: options.minItems,
118
121
  maxItems: options.maxItems,
119
122
  itemLabel: options.itemLabel,
123
+ layout,
124
+ gridColumns: options.gridColumns ?? 3,
125
+ collapsible: options.collapsible ?? (layout === 'list'),
120
126
  }) as ArrayFieldDef<TItem>
121
127
  },
122
128
 
@@ -134,6 +140,19 @@ export const f = {
134
140
  }) as ObjectFieldDef<TFields>
135
141
  },
136
142
 
143
+ date(options: DateFieldOptions): DateFieldDef {
144
+ return Object.freeze({
145
+ type: 'date' as const,
146
+ label: options.label,
147
+ description: options.description,
148
+ defaultValue: options.defaultValue ?? '',
149
+ required: options.required ?? false,
150
+ includeTime: options.includeTime ?? false,
151
+ min: options.min,
152
+ max: options.max,
153
+ })
154
+ },
155
+
137
156
  color(options: ColorFieldOptions): ColorFieldDef {
138
157
  return Object.freeze({
139
158
  type: 'color' as const,
@@ -16,6 +16,7 @@ export type FieldType =
16
16
  | 'object'
17
17
  | 'conditional'
18
18
  | 'color'
19
+ | 'date'
19
20
  | 'override'
20
21
 
21
22
  /** Path to a field in a nested schema (e.g. ['items', 0, 'title']) */
@@ -136,6 +137,9 @@ export interface ImageFieldDef extends FieldDefinition<'image', ImageValue> {
136
137
  readonly filenameStrategy: 'original' | 'slugified' | 'custom'
137
138
  }
138
139
 
140
+ /** Layout mode for array fields */
141
+ export type ArrayLayout = 'list' | 'grid'
142
+
139
143
  export interface ArrayFieldOptions {
140
144
  label: string
141
145
  description?: string
@@ -143,6 +147,12 @@ export interface ArrayFieldOptions {
143
147
  minItems?: number
144
148
  maxItems?: number
145
149
  itemLabel?: (item: unknown, index: number) => string
150
+ /** Display layout: 'list' (default, vertical) or 'grid' (cards) */
151
+ layout?: ArrayLayout
152
+ /** Columns for grid layout (default: 3) */
153
+ gridColumns?: number
154
+ /** Allow collapsing items (default: true for list, false for grid) */
155
+ collapsible?: boolean
146
156
  }
147
157
 
148
158
  export interface ArrayFieldDef<TItem extends FieldDefinition = FieldDefinition>
@@ -151,6 +161,9 @@ export interface ArrayFieldDef<TItem extends FieldDefinition = FieldDefinition>
151
161
  readonly minItems?: number
152
162
  readonly maxItems?: number
153
163
  readonly itemLabel?: (item: unknown, index: number) => string
164
+ readonly layout: ArrayLayout
165
+ readonly gridColumns: number
166
+ readonly collapsible: boolean
154
167
  }
155
168
 
156
169
  export interface ObjectFieldOptions {
@@ -168,6 +181,25 @@ export interface ObjectFieldDef<TFields extends FieldRecord = FieldRecord>
168
181
  readonly collapsible: boolean
169
182
  }
170
183
 
184
+ export interface DateFieldOptions {
185
+ label: string
186
+ description?: string
187
+ defaultValue?: string
188
+ required?: boolean
189
+ /** Include time picker (default: false = date only) */
190
+ includeTime?: boolean
191
+ /** Minimum date (ISO string, e.g. '2024-01-01') */
192
+ min?: string
193
+ /** Maximum date (ISO string) */
194
+ max?: string
195
+ }
196
+
197
+ export interface DateFieldDef extends FieldDefinition<'date', string> {
198
+ readonly includeTime: boolean
199
+ readonly min?: string
200
+ readonly max?: string
201
+ }
202
+
171
203
  export interface ColorFieldOptions {
172
204
  label: string
173
205
  description?: string
@@ -211,5 +243,6 @@ export type AnyFieldDef =
211
243
  | ImageFieldDef
212
244
  | ArrayFieldDef
213
245
  | ObjectFieldDef
246
+ | DateFieldDef
214
247
  | ColorFieldDef
215
248
  | OverrideFieldDef
@@ -31,6 +31,8 @@ export function fieldToZod(field: FieldDefinition): z.ZodType {
31
31
  return arrayToZod(field as ArrayFieldDef)
32
32
  case 'object':
33
33
  return objectToZod(field as ObjectFieldDef)
34
+ case 'date':
35
+ return dateToZod(field as AnyFieldDef & { type: 'date' })
34
36
  case 'color':
35
37
  return z.string().regex(/^#[0-9a-fA-F]{6}$/, 'Invalid hex color')
36
38
  case 'override':
@@ -69,6 +71,14 @@ function numberToZod(field: AnyFieldDef & { type: 'number' }): z.ZodType {
69
71
  return schema
70
72
  }
71
73
 
74
+ function dateToZod(field: AnyFieldDef & { type: 'date' }): z.ZodType {
75
+ let schema = z.string()
76
+ if (field.required) {
77
+ schema = schema.min(1, `${field.label} ist erforderlich`)
78
+ }
79
+ return schema
80
+ }
81
+
72
82
  function selectToZod(field: AnyFieldDef & { type: 'select' }): z.ZodType {
73
83
  const values = field.options.map((o) => o.value)
74
84
  if (values.length === 0) return z.string()