@panneau/protocol 5.0.0-alpha.0 → 5.0.0-alpha.10
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 +13 -8
- package/dist/conditions.d.ts +1 -1
- package/dist/conformance/index.d.ts.map +1 -1
- package/dist/conformance/index.js +310 -4
- package/dist/conformance/index.js.map +1 -1
- package/dist/constants.d.ts +44 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +128 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +4 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -15
- package/dist/libraries.d.ts +16 -0
- package/dist/libraries.d.ts.map +1 -0
- package/dist/libraries.js +15 -0
- package/dist/libraries.js.map +1 -0
- package/dist/lint.d.ts +4 -3
- package/dist/lint.d.ts.map +1 -1
- package/dist/lint.js +34 -2
- package/dist/lint.js.map +1 -1
- package/dist/mock/example.d.ts +3 -2
- package/dist/mock/example.d.ts.map +1 -1
- package/dist/mock/example.js +223 -138
- package/dist/mock/example.js.map +1 -1
- package/dist/mock/index.d.ts +19 -5
- package/dist/mock/index.d.ts.map +1 -1
- package/dist/mock/index.js +383 -19
- package/dist/mock/index.js.map +1 -1
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.d.ts.map +1 -1
- package/dist/openapi.js +113 -109
- package/dist/openapi.js.map +1 -1
- package/dist/problem.d.ts +7 -0
- package/dist/problem.d.ts.map +1 -0
- package/dist/problem.js +22 -0
- package/dist/problem.js.map +1 -0
- package/dist/query.d.ts +40 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +47 -6
- package/dist/query.js.map +1 -1
- package/dist/rules.d.ts +6 -3
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +51 -9
- package/dist/rules.js.map +1 -1
- package/dist/runtime/index.d.ts +14 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +13 -0
- package/dist/schemas/action.d.ts +69 -13
- package/dist/schemas/action.d.ts.map +1 -1
- package/dist/schemas/action.js +21 -14
- package/dist/schemas/action.js.map +1 -1
- package/dist/schemas/api.d.ts +224 -39
- package/dist/schemas/api.d.ts.map +1 -1
- package/dist/schemas/api.js +125 -31
- package/dist/schemas/api.js.map +1 -1
- package/dist/schemas/boot.d.ts +24 -6
- package/dist/schemas/boot.d.ts.map +1 -1
- package/dist/schemas/boot.js +3 -7
- package/dist/schemas/boot.js.map +1 -1
- package/dist/schemas/common.d.ts +1 -0
- package/dist/schemas/common.d.ts.map +1 -1
- package/dist/schemas/common.js +2 -1
- package/dist/schemas/common.js.map +1 -1
- package/dist/schemas/definition.d.ts +222 -20
- package/dist/schemas/definition.d.ts.map +1 -1
- package/dist/schemas/definition.js +16 -11
- package/dist/schemas/definition.js.map +1 -1
- package/dist/schemas/field.d.ts +162 -8
- package/dist/schemas/field.d.ts.map +1 -1
- package/dist/schemas/field.js +69 -49
- package/dist/schemas/field.js.map +1 -1
- package/dist/schemas/index.d.ts +955 -63
- package/dist/schemas/index.d.ts.map +1 -1
- package/dist/schemas/index.js +41 -12
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/jsonRules.d.ts +83 -0
- package/dist/schemas/jsonRules.d.ts.map +1 -0
- package/dist/schemas/jsonRules.js +46 -0
- package/dist/schemas/jsonRules.js.map +1 -0
- package/dist/schemas/layout.d.ts +1 -4
- package/dist/schemas/layout.d.ts.map +1 -1
- package/dist/schemas/layout.js +1 -13
- package/dist/schemas/layout.js.map +1 -1
- package/dist/schemas/list.d.ts +6 -3
- package/dist/schemas/list.d.ts.map +1 -1
- package/dist/schemas/list.js +3 -9
- package/dist/schemas/list.js.map +1 -1
- package/dist/schemas/resource.d.ts +144 -14
- package/dist/schemas/resource.d.ts.map +1 -1
- package/dist/schemas/resource.js +6 -1
- package/dist/schemas/resource.js.map +1 -1
- package/dist/schemas/theme.d.ts +179 -0
- package/dist/schemas/theme.d.ts.map +1 -0
- package/dist/schemas/theme.js +66 -0
- package/dist/schemas/theme.js.map +1 -0
- package/dist/search.d.ts +51 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +53 -0
- package/dist/search.js.map +1 -0
- package/dist/themes.d.ts +11 -0
- package/dist/themes.d.ts.map +1 -0
- package/dist/themes.js +80 -0
- package/dist/themes.js.map +1 -0
- package/dist/transforms.d.ts +17 -0
- package/dist/transforms.d.ts.map +1 -0
- package/dist/transforms.js +34 -0
- package/dist/transforms.js.map +1 -0
- package/dist/validate.d.ts +4 -6
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +24 -9
- package/dist/validate.js.map +1 -1
- package/dist/values.d.ts +5 -1
- package/dist/values.d.ts.map +1 -1
- package/dist/values.js +16 -2
- package/dist/values.js.map +1 -1
- package/package.json +12 -3
- package/schema/boot.schema.json +580 -16
- package/schema/definition.schema.json +577 -16
- package/schema/openapi.json +1818 -543
- package/schema/theme.schema.json +234 -0
package/dist/schemas/field.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { Condition } from './common';
|
|
3
|
-
/** Field types every Panneau frontend renders. Plugins add others. */
|
|
4
|
-
export declare const BUILT_IN_FIELD_TYPES: readonly ["text", "textarea", "richtext", "number", "boolean", "date", "datetime", "time", "select", "email", "url", "color", "media", "relation", "group", "repeater", "slug"];
|
|
5
|
-
/** Validation rules that both frontends and backends check. */
|
|
6
|
-
export declare const PORTABLE_RULES: readonly ["required", "min", "max", "pattern", "email", "url", "in", "accept", "maxSize", "before", "after"];
|
|
2
|
+
import { Condition } from './common.js';
|
|
7
3
|
export declare const Rule: z.ZodUnion<readonly [z.ZodObject<{
|
|
8
4
|
rule: z.ZodLiteral<"required">;
|
|
9
5
|
message: z.ZodOptional<z.ZodString>;
|
|
6
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
7
|
+
update: "update";
|
|
8
|
+
create: "create";
|
|
9
|
+
}>>;
|
|
10
10
|
}, z.core.$loose>, z.ZodObject<{
|
|
11
11
|
rule: z.ZodEnum<{
|
|
12
12
|
min: "min";
|
|
@@ -14,29 +14,54 @@ export declare const Rule: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
14
14
|
}>;
|
|
15
15
|
value: z.ZodNumber;
|
|
16
16
|
message: z.ZodOptional<z.ZodString>;
|
|
17
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
18
|
+
update: "update";
|
|
19
|
+
create: "create";
|
|
20
|
+
}>>;
|
|
17
21
|
}, z.core.$loose>, z.ZodObject<{
|
|
18
22
|
rule: z.ZodLiteral<"pattern">;
|
|
19
23
|
value: z.ZodString;
|
|
20
24
|
flags: z.ZodOptional<z.ZodString>;
|
|
21
25
|
message: z.ZodOptional<z.ZodString>;
|
|
26
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
27
|
+
update: "update";
|
|
28
|
+
create: "create";
|
|
29
|
+
}>>;
|
|
22
30
|
}, z.core.$loose>, z.ZodObject<{
|
|
23
31
|
rule: z.ZodEnum<{
|
|
24
32
|
email: "email";
|
|
25
33
|
url: "url";
|
|
34
|
+
json: "json";
|
|
26
35
|
}>;
|
|
27
36
|
message: z.ZodOptional<z.ZodString>;
|
|
37
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
38
|
+
update: "update";
|
|
39
|
+
create: "create";
|
|
40
|
+
}>>;
|
|
28
41
|
}, z.core.$loose>, z.ZodObject<{
|
|
29
42
|
rule: z.ZodLiteral<"in">;
|
|
30
43
|
value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
31
44
|
message: z.ZodOptional<z.ZodString>;
|
|
45
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
46
|
+
update: "update";
|
|
47
|
+
create: "create";
|
|
48
|
+
}>>;
|
|
32
49
|
}, z.core.$loose>, z.ZodObject<{
|
|
33
50
|
rule: z.ZodLiteral<"accept">;
|
|
34
51
|
value: z.ZodArray<z.ZodString>;
|
|
35
52
|
message: z.ZodOptional<z.ZodString>;
|
|
53
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
54
|
+
update: "update";
|
|
55
|
+
create: "create";
|
|
56
|
+
}>>;
|
|
36
57
|
}, z.core.$loose>, z.ZodObject<{
|
|
37
58
|
rule: z.ZodLiteral<"maxSize">;
|
|
38
59
|
value: z.ZodNumber;
|
|
39
60
|
message: z.ZodOptional<z.ZodString>;
|
|
61
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
62
|
+
update: "update";
|
|
63
|
+
create: "create";
|
|
64
|
+
}>>;
|
|
40
65
|
}, z.core.$loose>, z.ZodObject<{
|
|
41
66
|
rule: z.ZodEnum<{
|
|
42
67
|
before: "before";
|
|
@@ -46,9 +71,28 @@ export declare const Rule: z.ZodUnion<readonly [z.ZodObject<{
|
|
|
46
71
|
field: z.ZodString;
|
|
47
72
|
}, z.core.$loose>]>;
|
|
48
73
|
message: z.ZodOptional<z.ZodString>;
|
|
74
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
75
|
+
update: "update";
|
|
76
|
+
create: "create";
|
|
77
|
+
}>>;
|
|
78
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
79
|
+
rule: z.ZodLiteral<"crop">;
|
|
80
|
+
value: z.ZodObject<{
|
|
81
|
+
ratios: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
82
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
83
|
+
}, z.core.$loose>;
|
|
84
|
+
message: z.ZodOptional<z.ZodString>;
|
|
85
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
86
|
+
update: "update";
|
|
87
|
+
create: "create";
|
|
88
|
+
}>>;
|
|
49
89
|
}, z.core.$loose>, z.ZodObject<{
|
|
50
90
|
rule: z.ZodString;
|
|
51
91
|
message: z.ZodOptional<z.ZodString>;
|
|
92
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
93
|
+
update: "update";
|
|
94
|
+
create: "create";
|
|
95
|
+
}>>;
|
|
52
96
|
}, z.core.$loose>]>;
|
|
53
97
|
export declare const BlockType: z.ZodObject<{
|
|
54
98
|
id: z.ZodString;
|
|
@@ -70,6 +114,10 @@ export declare const Field: z.ZodObject<{
|
|
|
70
114
|
rules: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
|
|
71
115
|
rule: z.ZodLiteral<"required">;
|
|
72
116
|
message: z.ZodOptional<z.ZodString>;
|
|
117
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
118
|
+
update: "update";
|
|
119
|
+
create: "create";
|
|
120
|
+
}>>;
|
|
73
121
|
}, z.core.$loose>, z.ZodObject<{
|
|
74
122
|
rule: z.ZodEnum<{
|
|
75
123
|
min: "min";
|
|
@@ -77,29 +125,54 @@ export declare const Field: z.ZodObject<{
|
|
|
77
125
|
}>;
|
|
78
126
|
value: z.ZodNumber;
|
|
79
127
|
message: z.ZodOptional<z.ZodString>;
|
|
128
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
129
|
+
update: "update";
|
|
130
|
+
create: "create";
|
|
131
|
+
}>>;
|
|
80
132
|
}, z.core.$loose>, z.ZodObject<{
|
|
81
133
|
rule: z.ZodLiteral<"pattern">;
|
|
82
134
|
value: z.ZodString;
|
|
83
135
|
flags: z.ZodOptional<z.ZodString>;
|
|
84
136
|
message: z.ZodOptional<z.ZodString>;
|
|
137
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
138
|
+
update: "update";
|
|
139
|
+
create: "create";
|
|
140
|
+
}>>;
|
|
85
141
|
}, z.core.$loose>, z.ZodObject<{
|
|
86
142
|
rule: z.ZodEnum<{
|
|
87
143
|
email: "email";
|
|
88
144
|
url: "url";
|
|
145
|
+
json: "json";
|
|
89
146
|
}>;
|
|
90
147
|
message: z.ZodOptional<z.ZodString>;
|
|
148
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
149
|
+
update: "update";
|
|
150
|
+
create: "create";
|
|
151
|
+
}>>;
|
|
91
152
|
}, z.core.$loose>, z.ZodObject<{
|
|
92
153
|
rule: z.ZodLiteral<"in">;
|
|
93
154
|
value: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean]>>;
|
|
94
155
|
message: z.ZodOptional<z.ZodString>;
|
|
156
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
157
|
+
update: "update";
|
|
158
|
+
create: "create";
|
|
159
|
+
}>>;
|
|
95
160
|
}, z.core.$loose>, z.ZodObject<{
|
|
96
161
|
rule: z.ZodLiteral<"accept">;
|
|
97
162
|
value: z.ZodArray<z.ZodString>;
|
|
98
163
|
message: z.ZodOptional<z.ZodString>;
|
|
164
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
165
|
+
update: "update";
|
|
166
|
+
create: "create";
|
|
167
|
+
}>>;
|
|
99
168
|
}, z.core.$loose>, z.ZodObject<{
|
|
100
169
|
rule: z.ZodLiteral<"maxSize">;
|
|
101
170
|
value: z.ZodNumber;
|
|
102
171
|
message: z.ZodOptional<z.ZodString>;
|
|
172
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
173
|
+
update: "update";
|
|
174
|
+
create: "create";
|
|
175
|
+
}>>;
|
|
103
176
|
}, z.core.$loose>, z.ZodObject<{
|
|
104
177
|
rule: z.ZodEnum<{
|
|
105
178
|
before: "before";
|
|
@@ -109,9 +182,28 @@ export declare const Field: z.ZodObject<{
|
|
|
109
182
|
field: z.ZodString;
|
|
110
183
|
}, z.core.$loose>]>;
|
|
111
184
|
message: z.ZodOptional<z.ZodString>;
|
|
185
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
186
|
+
update: "update";
|
|
187
|
+
create: "create";
|
|
188
|
+
}>>;
|
|
189
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
190
|
+
rule: z.ZodLiteral<"crop">;
|
|
191
|
+
value: z.ZodObject<{
|
|
192
|
+
ratios: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
193
|
+
required: z.ZodOptional<z.ZodBoolean>;
|
|
194
|
+
}, z.core.$loose>;
|
|
195
|
+
message: z.ZodOptional<z.ZodString>;
|
|
196
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
197
|
+
update: "update";
|
|
198
|
+
create: "create";
|
|
199
|
+
}>>;
|
|
112
200
|
}, z.core.$loose>, z.ZodObject<{
|
|
113
201
|
rule: z.ZodString;
|
|
114
202
|
message: z.ZodOptional<z.ZodString>;
|
|
203
|
+
mode: z.ZodOptional<z.ZodEnum<{
|
|
204
|
+
update: "update";
|
|
205
|
+
create: "create";
|
|
206
|
+
}>>;
|
|
115
207
|
}, z.core.$loose>]>>>;
|
|
116
208
|
visibleWhen: z.ZodOptional<z.ZodObject<{
|
|
117
209
|
field: z.ZodOptional<z.ZodString>;
|
|
@@ -127,19 +219,81 @@ export declare const Field: z.ZodObject<{
|
|
|
127
219
|
label: z.ZodString;
|
|
128
220
|
description: z.ZodOptional<z.ZodString>;
|
|
129
221
|
disabled: z.ZodOptional<z.ZodBoolean>;
|
|
222
|
+
tone: z.ZodOptional<z.ZodString>;
|
|
130
223
|
}, z.core.$loose>>>;
|
|
131
224
|
multiple: z.ZodOptional<z.ZodBoolean>;
|
|
132
|
-
resource: z.ZodOptional<z.ZodString
|
|
225
|
+
resource: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>>;
|
|
133
226
|
accept: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
227
|
+
ratios: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
228
|
+
rotate: z.ZodOptional<z.ZodBoolean>;
|
|
229
|
+
focalPoint: z.ZodOptional<z.ZodBoolean>;
|
|
230
|
+
transformBase: z.ZodOptional<z.ZodEnum<{
|
|
231
|
+
media: "media";
|
|
232
|
+
original: "original";
|
|
233
|
+
choose: "choose";
|
|
234
|
+
}>>;
|
|
134
235
|
from: z.ZodOptional<z.ZodString>;
|
|
236
|
+
check: z.ZodOptional<z.ZodBoolean>;
|
|
135
237
|
display: z.ZodOptional<z.ZodString>;
|
|
136
238
|
fields: z.ZodOptional<z.ZodArray<typeof Field>>;
|
|
137
239
|
types: z.ZodOptional<z.ZodArray<typeof BlockType>>;
|
|
138
240
|
settings: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
139
241
|
}, z.core.$loose>;
|
|
140
|
-
|
|
141
|
-
export
|
|
242
|
+
/** A block style of a `richtext` field: a named class on an element (`<p class="big">`). */
|
|
243
|
+
export declare const RichTextStyle: z.ZodObject<{
|
|
244
|
+
label: z.ZodString;
|
|
245
|
+
class: z.ZodString;
|
|
246
|
+
element: z.ZodOptional<z.ZodEnum<{
|
|
247
|
+
p: "p";
|
|
248
|
+
h1: "h1";
|
|
249
|
+
h2: "h2";
|
|
250
|
+
h3: "h3";
|
|
251
|
+
h4: "h4";
|
|
252
|
+
h5: "h5";
|
|
253
|
+
h6: "h6";
|
|
254
|
+
blockquote: "blockquote";
|
|
255
|
+
ul: "ul";
|
|
256
|
+
ol: "ol";
|
|
257
|
+
li: "li";
|
|
258
|
+
}>>;
|
|
259
|
+
}, z.core.$loose>;
|
|
260
|
+
/**
|
|
261
|
+
* The `settings` of a `richtext` field: its toolbar, heading levels, block styles and which links
|
|
262
|
+
* open in a new tab. `validateDefinition()` checks them.
|
|
263
|
+
*/
|
|
264
|
+
export declare const RichTextSettings: z.ZodObject<{
|
|
265
|
+
toolbar: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
266
|
+
headings: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
267
|
+
styles: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
268
|
+
label: z.ZodString;
|
|
269
|
+
class: z.ZodString;
|
|
270
|
+
element: z.ZodOptional<z.ZodEnum<{
|
|
271
|
+
p: "p";
|
|
272
|
+
h1: "h1";
|
|
273
|
+
h2: "h2";
|
|
274
|
+
h3: "h3";
|
|
275
|
+
h4: "h4";
|
|
276
|
+
h5: "h5";
|
|
277
|
+
h6: "h6";
|
|
278
|
+
blockquote: "blockquote";
|
|
279
|
+
ul: "ul";
|
|
280
|
+
ol: "ol";
|
|
281
|
+
li: "li";
|
|
282
|
+
}>>;
|
|
283
|
+
}, z.core.$loose>>>;
|
|
284
|
+
links: z.ZodOptional<z.ZodObject<{
|
|
285
|
+
newTab: z.ZodOptional<z.ZodEnum<{
|
|
286
|
+
never: "never";
|
|
287
|
+
choose: "choose";
|
|
288
|
+
external: "external";
|
|
289
|
+
}>>;
|
|
290
|
+
}, z.core.$loose>>;
|
|
291
|
+
}, z.core.$loose>;
|
|
142
292
|
export type Rule = z.infer<typeof Rule>;
|
|
143
293
|
export type BlockType = z.infer<typeof BlockType>;
|
|
144
294
|
export type Field = z.infer<typeof Field>;
|
|
295
|
+
/** A block style of a `richtext` field. */
|
|
296
|
+
export type RichTextStyle = z.infer<typeof RichTextStyle>;
|
|
297
|
+
/** The `settings` of a `richtext` field. */
|
|
298
|
+
export type RichTextSettings = z.infer<typeof RichTextSettings>;
|
|
145
299
|
//# sourceMappingURL=field.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../src/schemas/field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../src/schemas/field.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,SAAS,EAAU,MAAM,UAAU,CAAC;AAsB7C,eAAO,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mBA8DX,CAAC;AAEP,eAAO,MAAM,SAAS;;;;YAKJ,CAAC,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC;iBAGxC,CAAC;AAEH,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA4DI,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,KAAK,CAAC,CAAC;WAMxC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,SAAS,CAAC,CAAC;;iBAQhB,CAAC;AAEjD,4FAA4F;AAC5F,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;iBAepB,CAAC;AAEP;;;GAGG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsBvB,CAAC;AAEP,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AACxC,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,SAAS,CAAC,CAAC;AAClD,MAAM,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,KAAK,CAAC,CAAC;AAC1C,2CAA2C;AAC3C,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAC1D,4CAA4C;AAC5C,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC"}
|
package/dist/schemas/field.js
CHANGED
|
@@ -1,61 +1,38 @@
|
|
|
1
|
+
import { PORTABLE_RULES, RICH_TEXT_STYLE_ELEMENTS } from "../constants.js";
|
|
1
2
|
import { Condition, Option } from "./common.js";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
//#region src/schemas/field.ts
|
|
4
|
-
/** Field types every Panneau frontend renders. Plugins add others. */
|
|
5
|
-
var BUILT_IN_FIELD_TYPES = [
|
|
6
|
-
"text",
|
|
7
|
-
"textarea",
|
|
8
|
-
"richtext",
|
|
9
|
-
"number",
|
|
10
|
-
"boolean",
|
|
11
|
-
"date",
|
|
12
|
-
"datetime",
|
|
13
|
-
"time",
|
|
14
|
-
"select",
|
|
15
|
-
"email",
|
|
16
|
-
"url",
|
|
17
|
-
"color",
|
|
18
|
-
"media",
|
|
19
|
-
"relation",
|
|
20
|
-
"group",
|
|
21
|
-
"repeater",
|
|
22
|
-
"slug"
|
|
23
|
-
];
|
|
24
|
-
/** Validation rules that both frontends and backends check. */
|
|
25
|
-
var PORTABLE_RULES = [
|
|
26
|
-
"required",
|
|
27
|
-
"min",
|
|
28
|
-
"max",
|
|
29
|
-
"pattern",
|
|
30
|
-
"email",
|
|
31
|
-
"url",
|
|
32
|
-
"in",
|
|
33
|
-
"accept",
|
|
34
|
-
"maxSize",
|
|
35
|
-
"before",
|
|
36
|
-
"after"
|
|
37
|
-
];
|
|
38
5
|
var message = z.string().optional().meta({ description: "Message shown when the rule fails, instead of the default one." });
|
|
6
|
+
var mode = z.enum(["create", "update"]).optional().meta({ description: "The rule only applies when the item is created (`create`) or updated (`update`): a password required to create a user, optional to edit one. Without it, the rule applies in both modes." });
|
|
7
|
+
var Ratio = z.string().regex(/^[1-9][0-9]*:[1-9][0-9]*$/).meta({ description: "An aspect ratio, as `width:height`: `16:9`." });
|
|
39
8
|
var DateBound = z.union([z.string().meta({ description: "An ISO 8601 date or date-time." }), z.looseObject({ field: z.string().min(1) }).meta({ description: "Another field of the form." })]);
|
|
40
9
|
var Rule = z.union([
|
|
41
10
|
z.looseObject({
|
|
42
11
|
rule: z.literal("required"),
|
|
43
|
-
message
|
|
12
|
+
message,
|
|
13
|
+
mode
|
|
44
14
|
}),
|
|
45
15
|
z.looseObject({
|
|
46
16
|
rule: z.enum(["min", "max"]),
|
|
47
17
|
value: z.number(),
|
|
48
|
-
message
|
|
18
|
+
message,
|
|
19
|
+
mode
|
|
49
20
|
}),
|
|
50
21
|
z.looseObject({
|
|
51
22
|
rule: z.literal("pattern"),
|
|
52
23
|
value: z.string(),
|
|
53
24
|
flags: z.string().optional(),
|
|
54
|
-
message
|
|
25
|
+
message,
|
|
26
|
+
mode
|
|
55
27
|
}),
|
|
56
28
|
z.looseObject({
|
|
57
|
-
rule: z.enum([
|
|
58
|
-
|
|
29
|
+
rule: z.enum([
|
|
30
|
+
"email",
|
|
31
|
+
"url",
|
|
32
|
+
"json"
|
|
33
|
+
]),
|
|
34
|
+
message,
|
|
35
|
+
mode
|
|
59
36
|
}),
|
|
60
37
|
z.looseObject({
|
|
61
38
|
rule: z.literal("in"),
|
|
@@ -64,28 +41,42 @@ var Rule = z.union([
|
|
|
64
41
|
z.number(),
|
|
65
42
|
z.boolean()
|
|
66
43
|
])),
|
|
67
|
-
message
|
|
44
|
+
message,
|
|
45
|
+
mode
|
|
68
46
|
}),
|
|
69
47
|
z.looseObject({
|
|
70
48
|
rule: z.literal("accept"),
|
|
71
49
|
value: z.array(z.string().min(1)),
|
|
72
|
-
message
|
|
50
|
+
message,
|
|
51
|
+
mode
|
|
73
52
|
}),
|
|
74
53
|
z.looseObject({
|
|
75
54
|
rule: z.literal("maxSize"),
|
|
76
55
|
value: z.number().int().positive(),
|
|
77
|
-
message
|
|
56
|
+
message,
|
|
57
|
+
mode
|
|
78
58
|
}),
|
|
79
59
|
z.looseObject({
|
|
80
60
|
rule: z.enum(["before", "after"]),
|
|
81
61
|
value: DateBound,
|
|
82
|
-
message
|
|
62
|
+
message,
|
|
63
|
+
mode
|
|
64
|
+
}),
|
|
65
|
+
z.looseObject({
|
|
66
|
+
rule: z.literal("crop"),
|
|
67
|
+
value: z.looseObject({
|
|
68
|
+
ratios: z.array(Ratio).optional().meta({ description: "A crop must have one of them: its height is within one pixel of its width divided by the ratio, after its rotation." }),
|
|
69
|
+
required: z.boolean().optional().meta({ description: "Each image needs a crop for this use." })
|
|
70
|
+
}),
|
|
71
|
+
message,
|
|
72
|
+
mode
|
|
83
73
|
}),
|
|
84
74
|
z.looseObject({
|
|
85
75
|
rule: z.string().refine((rule) => !PORTABLE_RULES.includes(rule)),
|
|
86
|
-
message
|
|
76
|
+
message,
|
|
77
|
+
mode
|
|
87
78
|
}).meta({ description: "A rule added in a later version of the protocol. Clients that don't know it ignore it; the server still enforces it." })
|
|
88
|
-
]).meta({ description: "A portable validation rule. `min` and `max` apply to numbers, and to the length of text and arrays. `accept` lists MIME types (`image/*`). `maxSize` is in bytes." });
|
|
79
|
+
]).meta({ description: "A portable validation rule. `min` and `max` apply to numbers, and to the length of text and arrays. `accept` lists MIME types (`image/*`). `maxSize` is in bytes. `crop` checks the transform of each image of an `image` or `media` value (decision 0031)." });
|
|
89
80
|
var BlockType = z.looseObject({
|
|
90
81
|
id: z.string().min(1),
|
|
91
82
|
label: z.string(),
|
|
@@ -108,10 +99,19 @@ var Field = z.looseObject({
|
|
|
108
99
|
rules: z.array(Rule).optional(),
|
|
109
100
|
visibleWhen: Condition.optional(),
|
|
110
101
|
options: z.array(Option).optional().meta({ description: "`select`: the choices." }),
|
|
111
|
-
multiple: z.boolean().optional().meta({ description: "`select`, `relation`, `media`: the value is an array." }),
|
|
112
|
-
resource: z.string().optional().meta({ description: "`relation`: id of the related resource." }),
|
|
113
|
-
accept: z.array(z.string()).optional().meta({ description: "`media`: accepted MIME types." }),
|
|
102
|
+
multiple: z.boolean().optional().meta({ description: "`select`, `relation`, `media`, `image`, `file`: the value is an array." }),
|
|
103
|
+
resource: z.union([z.string().min(1), z.array(z.string().min(1)).min(1)]).optional().meta({ description: "`relation`: id of the related resource. `media`, `image`: id of a resource of kind `media`, or a list of them; without it, every library of the definition (decision 0027)." }),
|
|
104
|
+
accept: z.array(z.string()).optional().meta({ description: "`media`, `image`, `file`: accepted MIME types. `image` defaults to `image/*`." }),
|
|
105
|
+
ratios: z.array(Ratio).optional().meta({ description: "`image`: ratios the editor suggests. The `crop` rule enforces ratios (decision 0031)." }),
|
|
106
|
+
rotate: z.boolean().optional().meta({ description: "`image`: whether the editor offers rotation and flips. Defaults to true." }),
|
|
107
|
+
focalPoint: z.boolean().optional().meta({ description: "`image`: whether the editor offers the focal point. Defaults to true." }),
|
|
108
|
+
transformBase: z.enum([
|
|
109
|
+
"media",
|
|
110
|
+
"original",
|
|
111
|
+
"choose"
|
|
112
|
+
]).optional().meta({ description: "`image`: what a transform for one use starts from: the media's own transform (`media`, the default), the original file, or the user's choice in the editor (decision 0031)." }),
|
|
114
113
|
from: z.string().optional().meta({ description: "`slug`: the field the slug is generated from." }),
|
|
114
|
+
check: z.boolean().optional().meta({ description: "The client checks the value with the backend as it is typed, with `POST /resources/{resource}/fields/{field}/check`: whether a `slug` is available, and its URL. A field at the top of the resource only." }),
|
|
115
115
|
display: z.string().optional().meta({ description: "Display used in lists, when it differs from the default one of the type." }),
|
|
116
116
|
get fields() {
|
|
117
117
|
return z.array(Field).optional().meta({ description: "`group` and `repeater`: the nested fields." });
|
|
@@ -121,7 +121,27 @@ var Field = z.looseObject({
|
|
|
121
121
|
},
|
|
122
122
|
settings: z.record(z.string(), z.unknown()).optional()
|
|
123
123
|
}).meta({ description: "A field of a form." });
|
|
124
|
+
/** A block style of a `richtext` field: a named class on an element (`<p class="big">`). */
|
|
125
|
+
var RichTextStyle = z.looseObject({
|
|
126
|
+
label: z.string().meta({ description: "The name of the style in the toolbar." }),
|
|
127
|
+
class: z.string().min(1).meta({ description: "The class the style puts on the element: `big`. Several classes are separated by spaces." }),
|
|
128
|
+
element: z.enum(RICH_TEXT_STYLE_ELEMENTS).optional().meta({ description: "The element the style applies to: `p` (the default), `h1` to `h6`, `blockquote`, `ul`, `ol` or `li`." })
|
|
129
|
+
}).meta({ description: "A block style of a `richtext` field: a named class on a paragraph, a heading, a quote or a list (`<p class=\"big\">`)." });
|
|
130
|
+
/**
|
|
131
|
+
* The `settings` of a `richtext` field: its toolbar, heading levels, block styles and which links
|
|
132
|
+
* open in a new tab. `validateDefinition()` checks them.
|
|
133
|
+
*/
|
|
134
|
+
var RichTextSettings = z.looseObject({
|
|
135
|
+
toolbar: z.array(z.string().min(1)).optional().meta({ description: "The toolbar, in order: `heading`, `style`, `bold`, `italic`, `underline`, `strike`, `superscript`, `subscript`, `code`, `link`, `bulletList`, `orderedList`, `blockquote`, `horizontalRule`, `clear`, `undo`, `redo`, `|` between groups, and the buttons of plugins. Clients skip the names they don't know." }),
|
|
136
|
+
headings: z.array(z.number().int().min(1).max(6)).optional().meta({ description: "The heading levels the toolbar offers. Defaults to 2, 3 and 4." }),
|
|
137
|
+
styles: z.array(RichTextStyle).optional().meta({ description: "The block styles." }),
|
|
138
|
+
links: z.looseObject({ newTab: z.enum([
|
|
139
|
+
"choose",
|
|
140
|
+
"external",
|
|
141
|
+
"never"
|
|
142
|
+
]).optional().meta({ description: "Which links open in a new tab (`target=\"_blank\" rel=\"noopener noreferrer\"`): as the user chooses (the default), every link to another site, or none." }) }).optional()
|
|
143
|
+
}).meta({ description: "The `settings` of a `richtext` field. Its value is HTML. The toolbar only limits what users add: content that the field stores keeps its elements and attributes." });
|
|
124
144
|
//#endregion
|
|
125
|
-
export {
|
|
145
|
+
export { BlockType, Field, RichTextSettings, RichTextStyle, Rule };
|
|
126
146
|
|
|
127
147
|
//# sourceMappingURL=field.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.js","names":[],"sources":["../../src/schemas/field.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { Condition, Option } from './common';\n\n/** Field types every Panneau frontend renders. Plugins add others. */\nexport const BUILT_IN_FIELD_TYPES = [\n 'text',\n 'textarea',\n 'richtext',\n 'number',\n 'boolean',\n 'date',\n 'datetime',\n 'time',\n 'select',\n 'email',\n 'url',\n 'color',\n 'media',\n 'relation',\n 'group',\n 'repeater',\n 'slug',\n] as const;\n\n/** Validation rules that both frontends and backends check. */\nexport const PORTABLE_RULES = [\n 'required',\n 'min',\n 'max',\n 'pattern',\n 'email',\n 'url',\n 'in',\n 'accept',\n 'maxSize',\n 'before',\n 'after',\n] as const;\n\nconst message = z\n .string()\n .optional()\n .meta({ description: 'Message shown when the rule fails, instead of the default one.' });\n\nconst DateBound = z.union([\n z.string().meta({ description: 'An ISO 8601 date or date-time.' }),\n z.looseObject({ field: z.string().min(1) }).meta({ description: 'Another field of the form.' }),\n]);\n\nexport const Rule = z\n .union([\n z.looseObject({ rule: z.literal('required'), message }),\n z.looseObject({ rule: z.enum(['min', 'max']), value: z.number(), message }),\n z.looseObject({\n rule: z.literal('pattern'),\n value: z.string(),\n flags: z.string().optional(),\n message,\n }),\n z.looseObject({ rule: z.enum(['email', 'url']), message }),\n z.looseObject({\n rule: z.literal('in'),\n value: z.array(z.union([z.string(), z.number(), z.boolean()])),\n message,\n }),\n z.looseObject({ rule: z.literal('accept'), value: z.array(z.string().min(1)), message }),\n z.looseObject({ rule: z.literal('maxSize'), value: z.number().int().positive(), message }),\n z.looseObject({ rule: z.enum(['before', 'after']), value: DateBound, message }),\n z\n .looseObject({\n rule: z\n .string()\n .refine((rule) => !(PORTABLE_RULES as readonly string[]).includes(rule)),\n message,\n })\n .meta({\n description:\n \"A rule added in a later version of the protocol. Clients that don't know it ignore it; the server still enforces it.\",\n }),\n ])\n .meta({\n description:\n 'A portable validation rule. `min` and `max` apply to numbers, and to the length of text and arrays. `accept` lists MIME types (`image/*`). `maxSize` is in bytes.',\n });\n\nexport const BlockType = z.looseObject({\n id: z.string().min(1),\n label: z.string(),\n icon: z.string().optional(),\n // Return types are written out so that declaration files keep the recursion.\n get fields(): z.ZodArray<typeof Field> {\n return z.array(Field);\n },\n});\n\nexport const Field = z\n .looseObject({\n name: z.string().min(1),\n type: z\n .string()\n .min(1)\n .meta({ description: 'A built-in field type, or a type provided by a plugin.' }),\n label: z.string().optional(),\n help: z.string().optional(),\n placeholder: z.string().optional(),\n default: z.unknown().optional(),\n localized: z\n .boolean()\n .optional()\n .meta({ description: 'The value is an object keyed by locale.' }),\n readOnly: z.boolean().optional(),\n createOnly: z.boolean().optional(),\n updateOnly: z.boolean().optional(),\n rules: z.array(Rule).optional(),\n visibleWhen: Condition.optional(),\n options: z.array(Option).optional().meta({ description: '`select`: the choices.' }),\n multiple: z\n .boolean()\n .optional()\n .meta({ description: '`select`, `relation`, `media`: the value is an array.' }),\n resource: z\n .string()\n .optional()\n .meta({ description: '`relation`: id of the related resource.' }),\n accept: z\n .array(z.string())\n .optional()\n .meta({ description: '`media`: accepted MIME types.' }),\n from: z\n .string()\n .optional()\n .meta({ description: '`slug`: the field the slug is generated from.' }),\n display: z.string().optional().meta({\n description: 'Display used in lists, when it differs from the default one of the type.',\n }),\n get fields(): z.ZodOptional<z.ZodArray<typeof Field>> {\n return z\n .array(Field)\n .optional()\n .meta({ description: '`group` and `repeater`: the nested fields.' });\n },\n get types(): z.ZodOptional<z.ZodArray<typeof BlockType>> {\n return z\n .array(BlockType)\n .optional()\n .meta({ description: '`repeater`: typed blocks, each with its own fields.' });\n },\n settings: z.record(z.string(), z.unknown()).optional(),\n })\n .meta({ description: 'A field of a form.' });\n\nexport type BuiltInFieldType = (typeof BUILT_IN_FIELD_TYPES)[number];\nexport type PortableRule = (typeof PORTABLE_RULES)[number];\nexport type Rule = z.infer<typeof Rule>;\nexport type BlockType = z.infer<typeof BlockType>;\nexport type Field = z.infer<typeof Field>;\n"],"mappings":";;;;AAKA,IAAa,uBAAuB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;;AAGA,IAAa,iBAAiB;CAC1B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACJ;AAEA,IAAM,UAAU,EACX,OAAO,CAAC,CACR,SAAS,CAAC,CACV,KAAK,EAAE,aAAa,iEAAiE,CAAC;AAE3F,IAAM,YAAY,EAAE,MAAM,CACtB,EAAE,OAAO,CAAC,CAAC,KAAK,EAAE,aAAa,iCAAiC,CAAC,GACjE,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,EA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CACR,SAAS,CAAC,CACV,KAAK,EAAE,aAAa,gDAAgD,CAAC;CAC1E,SAAS,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,KAAK,EAChC,aAAa,2EACjB,CAAC;CACD,IAAI,SAAkD;EAClD,OAAO,EACF,MAAM,KAAK,CAAC,CACZ,SAAS,CAAC,CACV,KAAK,EAAE,aAAa,6CAA6C,CAAC;CAC3E;CACA,IAAI,QAAqD;EACrD,OAAO,EACF,MAAM,SAAS,CAAC,CAChB,SAAS,CAAC,CACV,KAAK,EAAE,aAAa,sDAAsD,CAAC;CACpF;CACA,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS;AACzD,CAAC,CAAC,CACD,KAAK,EAAE,aAAa,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"field.js","names":[],"sources":["../../src/schemas/field.ts"],"sourcesContent":["import { z } from 'zod';\n\nimport { PORTABLE_RULES, RICH_TEXT_STYLE_ELEMENTS } from '../constants';\nimport { Condition, Option } from './common';\n\nconst message = z\n .string()\n .optional()\n .meta({ description: 'Message shown when the rule fails, instead of the default one.' });\n\nconst mode = z.enum(['create', 'update']).optional().meta({\n description:\n 'The rule only applies when the item is created (`create`) or updated (`update`): a password required to create a user, optional to edit one. Without it, the rule applies in both modes.',\n});\n\nconst Ratio = z\n .string()\n .regex(/^[1-9][0-9]*:[1-9][0-9]*$/)\n .meta({ description: 'An aspect ratio, as `width:height`: `16:9`.' });\n\nconst DateBound = z.union([\n z.string().meta({ description: 'An ISO 8601 date or date-time.' }),\n z.looseObject({ field: z.string().min(1) }).meta({ description: 'Another field of the form.' }),\n]);\n\nexport const Rule = z\n .union([\n z.looseObject({ rule: z.literal('required'), message, mode }),\n z.looseObject({ rule: z.enum(['min', 'max']), value: z.number(), message, mode }),\n z.looseObject({\n rule: z.literal('pattern'),\n value: z.string(),\n flags: z.string().optional(),\n message,\n mode,\n }),\n z.looseObject({ rule: z.enum(['email', 'url', 'json']), message, mode }),\n z.looseObject({\n rule: z.literal('in'),\n value: z.array(z.union([z.string(), z.number(), z.boolean()])),\n message,\n mode,\n }),\n z.looseObject({\n rule: z.literal('accept'),\n value: z.array(z.string().min(1)),\n message,\n mode,\n }),\n z.looseObject({\n rule: z.literal('maxSize'),\n value: z.number().int().positive(),\n message,\n mode,\n }),\n z.looseObject({ rule: z.enum(['before', 'after']), value: DateBound, message, mode }),\n z.looseObject({\n rule: z.literal('crop'),\n value: z.looseObject({\n ratios: z.array(Ratio).optional().meta({\n description:\n 'A crop must have one of them: its height is within one pixel of its width divided by the ratio, after its rotation.',\n }),\n required: z\n .boolean()\n .optional()\n .meta({ description: 'Each image needs a crop for this use.' }),\n }),\n message,\n mode,\n }),\n z\n .looseObject({\n rule: z\n .string()\n .refine((rule) => !(PORTABLE_RULES as readonly string[]).includes(rule)),\n message,\n mode,\n })\n .meta({\n description:\n \"A rule added in a later version of the protocol. Clients that don't know it ignore it; the server still enforces it.\",\n }),\n ])\n .meta({\n description:\n 'A portable validation rule. `min` and `max` apply to numbers, and to the length of text and arrays. `accept` lists MIME types (`image/*`). `maxSize` is in bytes. `crop` checks the transform of each image of an `image` or `media` value (decision 0031).',\n });\n\nexport const BlockType = z.looseObject({\n id: z.string().min(1),\n label: z.string(),\n icon: z.string().optional(),\n // Return types are written out so that declaration files keep the recursion.\n get fields(): z.ZodArray<typeof Field> {\n return z.array(Field);\n },\n});\n\nexport const Field = z\n .looseObject({\n name: z.string().min(1),\n type: z\n .string()\n .min(1)\n .meta({ description: 'A built-in field type, or a type provided by a plugin.' }),\n label: z.string().optional(),\n help: z.string().optional(),\n placeholder: z.string().optional(),\n default: z.unknown().optional(),\n localized: z\n .boolean()\n .optional()\n .meta({ description: 'The value is an object keyed by locale.' }),\n readOnly: z.boolean().optional(),\n createOnly: z.boolean().optional(),\n updateOnly: z.boolean().optional(),\n rules: z.array(Rule).optional(),\n visibleWhen: Condition.optional(),\n options: z.array(Option).optional().meta({ description: '`select`: the choices.' }),\n multiple: z.boolean().optional().meta({\n description: '`select`, `relation`, `media`, `image`, `file`: the value is an array.',\n }),\n resource: z\n .union([z.string().min(1), z.array(z.string().min(1)).min(1)])\n .optional()\n .meta({\n description:\n '`relation`: id of the related resource. `media`, `image`: id of a resource of kind `media`, or a list of them; without it, every library of the definition (decision 0027).',\n }),\n accept: z.array(z.string()).optional().meta({\n description:\n '`media`, `image`, `file`: accepted MIME types. `image` defaults to `image/*`.',\n }),\n ratios: z.array(Ratio).optional().meta({\n description:\n '`image`: ratios the editor suggests. The `crop` rule enforces ratios (decision 0031).',\n }),\n rotate: z.boolean().optional().meta({\n description: '`image`: whether the editor offers rotation and flips. Defaults to true.',\n }),\n focalPoint: z.boolean().optional().meta({\n description: '`image`: whether the editor offers the focal point. Defaults to true.',\n }),\n transformBase: z.enum(['media', 'original', 'choose']).optional().meta({\n description:\n \"`image`: what a transform for one use starts from: the media's own transform (`media`, the default), the original file, or the user's choice in the editor (decision 0031).\",\n }),\n from: z\n .string()\n .optional()\n .meta({ description: '`slug`: the field the slug is generated from.' }),\n check: z.boolean().optional().meta({\n description:\n 'The client checks the value with the backend as it is typed, with `POST /resources/{resource}/fields/{field}/check`: whether a `slug` is available, and its URL. A field at the top of the resource only.',\n }),\n display: z.string().optional().meta({\n description: 'Display used in lists, when it differs from the default one of the type.',\n }),\n get fields(): z.ZodOptional<z.ZodArray<typeof Field>> {\n return z\n .array(Field)\n .optional()\n .meta({ description: '`group` and `repeater`: the nested fields.' });\n },\n get types(): z.ZodOptional<z.ZodArray<typeof BlockType>> {\n return z\n .array(BlockType)\n .optional()\n .meta({ description: '`repeater`: typed blocks, each with its own fields.' });\n },\n settings: z.record(z.string(), z.unknown()).optional(),\n })\n .meta({ description: 'A field of a form.' });\n\n/** A block style of a `richtext` field: a named class on an element (`<p class=\"big\">`). */\nexport const RichTextStyle = z\n .looseObject({\n label: z.string().meta({ description: 'The name of the style in the toolbar.' }),\n class: z.string().min(1).meta({\n description:\n 'The class the style puts on the element: `big`. Several classes are separated by spaces.',\n }),\n element: z.enum(RICH_TEXT_STYLE_ELEMENTS).optional().meta({\n description:\n 'The element the style applies to: `p` (the default), `h1` to `h6`, `blockquote`, `ul`, `ol` or `li`.',\n }),\n })\n .meta({\n description:\n 'A block style of a `richtext` field: a named class on a paragraph, a heading, a quote or a list (`<p class=\"big\">`).',\n });\n\n/**\n * The `settings` of a `richtext` field: its toolbar, heading levels, block styles and which links\n * open in a new tab. `validateDefinition()` checks them.\n */\nexport const RichTextSettings = z\n .looseObject({\n toolbar: z.array(z.string().min(1)).optional().meta({\n description:\n \"The toolbar, in order: `heading`, `style`, `bold`, `italic`, `underline`, `strike`, `superscript`, `subscript`, `code`, `link`, `bulletList`, `orderedList`, `blockquote`, `horizontalRule`, `clear`, `undo`, `redo`, `|` between groups, and the buttons of plugins. Clients skip the names they don't know.\",\n }),\n headings: z.array(z.number().int().min(1).max(6)).optional().meta({\n description: 'The heading levels the toolbar offers. Defaults to 2, 3 and 4.',\n }),\n styles: z.array(RichTextStyle).optional().meta({ description: 'The block styles.' }),\n links: z\n .looseObject({\n newTab: z.enum(['choose', 'external', 'never']).optional().meta({\n description:\n 'Which links open in a new tab (`target=\"_blank\" rel=\"noopener noreferrer\"`): as the user chooses (the default), every link to another site, or none.',\n }),\n })\n .optional(),\n })\n .meta({\n description:\n 'The `settings` of a `richtext` field. Its value is HTML. The toolbar only limits what users add: content that the field stores keeps its elements and attributes.',\n });\n\nexport type Rule = z.infer<typeof Rule>;\nexport type BlockType = z.infer<typeof BlockType>;\nexport type Field = z.infer<typeof Field>;\n/** A block style of a `richtext` field. */\nexport type RichTextStyle = z.infer<typeof RichTextStyle>;\n/** The `settings` of a `richtext` field. */\nexport type RichTextSettings = z.infer<typeof RichTextSettings>;\n"],"mappings":";;;;AAKA,IAAM,UAAU,EACX,OAAO,CAAC,CACR,SAAS,CAAC,CACV,KAAK,EAAE,aAAa,iEAAiE,CAAC;AAE3F,IAAM,OAAO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