@tinacms/schema-tools 0.0.0-00f6525-20241015065741

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.
@@ -0,0 +1,836 @@
1
+ import type { FC } from 'react';
2
+ import type React from 'react';
3
+ type Meta = {
4
+ active?: boolean;
5
+ dirty?: boolean;
6
+ error?: any;
7
+ };
8
+ type FilterValue = string[] | string;
9
+ type Component<Type, List> = (props: {
10
+ field: TinaField & {
11
+ namespace: string[];
12
+ };
13
+ input: {
14
+ /**
15
+ * The full name of the field, for fields nested inside object
16
+ * fields, this will be the full path:
17
+ *
18
+ * `myObject.0.title`
19
+ */
20
+ name: string;
21
+ onBlur: (event?: React.FocusEvent<Type>) => void;
22
+ /**
23
+ * The value provided will be saved to the form so it
24
+ * should match the configured type:
25
+ *
26
+ * `input.onChange('some string')`
27
+ */
28
+ onChange: (event: React.ChangeEvent<Type>) => void;
29
+ onFocus: (event?: React.FocusEvent<Type>) => void;
30
+ type?: string;
31
+ value: List extends true ? Type[] : Type;
32
+ };
33
+ meta: Meta;
34
+ }) => any;
35
+ export type UIField<Type, List extends boolean> = {
36
+ max?: List extends true ? number : never;
37
+ min?: List extends true ? number : never;
38
+ /**
39
+ * Override the label from parent object
40
+ */
41
+ label?: string;
42
+ /**
43
+ * Override the description from parent object
44
+ */
45
+ description?: string;
46
+ /**
47
+ * A React component which will be used in the Tina form. Be sure
48
+ * to import React into the config file.
49
+ *
50
+ * Note: Any Tailwind classes provided here will be compiled as part
51
+ * of the Tina stylesheet
52
+ *
53
+ * eg:
54
+ * ```tsx
55
+ * component: (props) => {
56
+ * const { input, field } = props
57
+ * return (
58
+ * <div className="my-4">
59
+ * <label
60
+ * htmlFor={input.name}
61
+ * className="block text-sm font-medium"
62
+ * >
63
+ * {field.name}
64
+ * </label>
65
+ * <div className="mt-1">
66
+ * <input
67
+ * id={input.name}
68
+ * className="py-2 px-4 block"
69
+ * type="text"
70
+ * {...input}
71
+ * />
72
+ * </div>
73
+ * </div>
74
+ * )
75
+ * }
76
+ * ```
77
+ *
78
+ * Note: If the form has already been registered with the cms, you
79
+ * can provide it's name here (eg. `textarea`)
80
+ */
81
+ component?: Component<Type, List> | string | null;
82
+ /**
83
+ * Optional: Prepare data for use in the component. This is useful
84
+ * if you don't have access to the component directly
85
+ */
86
+ parse?: (value: List extends true ? Type[] : Type, name: string, field: Field) => List extends true ? Type[] : Type;
87
+ /**
88
+ * Optional: Prepare data for saving. This is useful
89
+ * if you don't have access to the component directly
90
+ */
91
+ format?: (value: Type, name: string, field: Field) => List extends true ? Type[] : Type;
92
+ /**
93
+ * Optional: Return undefined when valid. Return a string or an object when there are errors.
94
+ *
95
+ * ```ts
96
+ * validate: (value) => {
97
+ * if(value.length > 40){
98
+ * return 'Title cannot be more than 40 characters long'
99
+ * }
100
+ * }
101
+ * ```
102
+ */
103
+ validate?(value: List extends true ? Type[] : Type, allValues: {
104
+ [key: string]: any;
105
+ }, meta: Meta, field: UIField<Type, List>): string | undefined | void;
106
+ /**
107
+ * @deprecated use `defaultItem` at the collection level instead
108
+ */
109
+ defaultValue?: List extends true ? Type[] : Type;
110
+ };
111
+ type FieldGeneric<Type, List extends boolean | undefined, ExtraFieldUIProps = {}> = List extends true ? {
112
+ list: true;
113
+ ui?: UIField<Type, true> & ExtraFieldUIProps;
114
+ } : List extends false ? {
115
+ list?: false;
116
+ ui?: UIField<Type, false> & ExtraFieldUIProps;
117
+ } : {
118
+ list?: undefined;
119
+ ui?: UIField<Type, false> & ExtraFieldUIProps;
120
+ };
121
+ type SearchableTextField = {
122
+ maxSearchIndexFieldLength?: number;
123
+ };
124
+ export interface BaseField {
125
+ label?: string | boolean;
126
+ required?: boolean;
127
+ indexed?: boolean;
128
+ name: string;
129
+ nameOverride?: string;
130
+ description?: string;
131
+ searchable?: boolean;
132
+ uid?: boolean;
133
+ }
134
+ export type StringField = (FieldGeneric<string, undefined> | FieldGeneric<string, true> | FieldGeneric<string, false>) & BaseField & SearchableTextField & {
135
+ type: 'string';
136
+ isTitle?: boolean;
137
+ isBody?: boolean;
138
+ options?: Option[];
139
+ };
140
+ export type NumberField = (FieldGeneric<number, undefined> | FieldGeneric<number, true> | FieldGeneric<number, false>) & BaseField & {
141
+ type: 'number';
142
+ };
143
+ export type BooleanField = (FieldGeneric<boolean, undefined> | FieldGeneric<boolean, true> | FieldGeneric<boolean, false>) & BaseField & {
144
+ type: 'boolean';
145
+ };
146
+ type DateFormatProps = {
147
+ /**
148
+ * Customize the way the format is rendered
149
+ * ```
150
+ * dateFormat: 'YYYY MM DD'
151
+ * ```
152
+ */
153
+ dateFormat?: string;
154
+ timeFormat?: string;
155
+ };
156
+ export type DateTimeField = (FieldGeneric<string, undefined, DateFormatProps> | FieldGeneric<string, true, DateFormatProps> | FieldGeneric<string, false, DateFormatProps>) & BaseField & {
157
+ type: 'datetime';
158
+ };
159
+ export type ImageField = (FieldGeneric<string, undefined> | FieldGeneric<string, true> | FieldGeneric<string, false>) & BaseField & {
160
+ type: 'image';
161
+ };
162
+ type ReferenceFieldOptions = {
163
+ optionComponent?: OptionComponent;
164
+ /**
165
+ * @deprecated use `collectionFilter` instead as experimental___Filter will be removed in a future release
166
+ */
167
+ experimental___filter?: (list: Array<any>, searchQuery: string) => Array<any>;
168
+ collectionFilter?: Record<string, Record<string, FilterValue>> | (() => Record<string, Record<string, FilterValue>>);
169
+ };
170
+ type OptionComponent<P = Record<string, unknown>, S = Document['_sys']> = (props: P, _internalSys: S) => React.ReactNode | Element | undefined;
171
+ export type ReferenceField = (FieldGeneric<string, undefined, ReferenceFieldOptions> | FieldGeneric<string, false, ReferenceFieldOptions>) & BaseField & {
172
+ type: 'reference';
173
+ /**
174
+ * The names of the collections this field can use as a reference
175
+ * ```ts
176
+ * {
177
+ * type: 'reference',
178
+ * name: 'author',
179
+ * collections: ['author'],
180
+ * }
181
+ * ```
182
+ */
183
+ collections: string[];
184
+ };
185
+ export type PasswordField = (FieldGeneric<string, undefined> | FieldGeneric<string, false>) & BaseField & {
186
+ type: 'password';
187
+ };
188
+ type toolbarItemName = 'heading' | 'link' | 'image' | 'quote' | 'ul' | 'ol' | 'code' | 'codeBlock' | 'bold' | 'italic' | 'raw' | 'embed' | 'mermaid';
189
+ type RichTextAst = {
190
+ type: 'root';
191
+ children: Record<string, unknown>[];
192
+ };
193
+ export type RichTextField<WithNamespace extends boolean = false> = (FieldGeneric<RichTextAst, undefined> | FieldGeneric<RichTextAst, false>) & BaseField & SearchableTextField & {
194
+ type: 'rich-text';
195
+ /**
196
+ * When using Markdown or MDX formats, this field's value
197
+ * will be saved to the markdown body, while all other values
198
+ * will be stored as frontmatter
199
+ */
200
+ isBody?: boolean;
201
+ toolbarOverride?: toolbarItemName[];
202
+ templates?: RichTextTemplate<WithNamespace>[];
203
+ /**
204
+ * By default, Tina parses markdown with MDX, this is a more strict parser
205
+ * that allows you to use structured content inside markdown (via `templates`).
206
+ *
207
+ * Specify `"markdown"` if you're having problems with Tina parsing your content.
208
+ */
209
+ parser?: {
210
+ type: 'markdown';
211
+ /**
212
+ * Tina will escape entities like `<` and `[` by default. You can choose to turn
213
+ * off all escaping, or specify HTML, so `<div>` will not be turned into `\<div>`
214
+ */
215
+ skipEscaping?: 'all' | 'html' | 'none';
216
+ } | {
217
+ type: 'mdx';
218
+ };
219
+ };
220
+ export type RichTextTemplate<WithNamespace extends boolean = false> = Template<WithNamespace> & {
221
+ inline?: boolean;
222
+ /**
223
+ * If you have some custom shortcode logic in your markdown,
224
+ * you can specify it in the 'match' property and Tina will
225
+ * handle it as if it were a jsx element:
226
+ *
227
+ * ```
228
+ * # This is my markdown, it uses some custom shortcode
229
+ * syntax {{ myshortcode title="hello!" }}.
230
+ *
231
+ * {
232
+ * match: {
233
+ * start: "{{"
234
+ * end: "}}"
235
+ * }
236
+ * }
237
+ * ```
238
+ */
239
+ match?: {
240
+ start: string;
241
+ end: string;
242
+ name?: string;
243
+ };
244
+ };
245
+ type ObjectUiProps = {
246
+ visualSelector?: boolean;
247
+ };
248
+ export type ObjectField<WithNamespace extends boolean = false> = (FieldGeneric<string, undefined, ObjectUiProps> | FieldGeneric<string, true, ObjectUiProps> | FieldGeneric<string, false, ObjectUiProps>) & MaybeNamespace<WithNamespace> & BaseField & ({
249
+ type: 'object';
250
+ fields: Field<WithNamespace>[];
251
+ templates?: undefined;
252
+ ui?: Template['ui'];
253
+ } | {
254
+ type: 'object';
255
+ fields?: undefined;
256
+ templates: Template<WithNamespace>[];
257
+ templateKey?: string;
258
+ });
259
+ type Field<WithNamespace extends boolean = false> = (StringField | NumberField | BooleanField | DateTimeField | ImageField | ReferenceField | RichTextField<WithNamespace> | ObjectField<WithNamespace> | PasswordField) & MaybeNamespace<WithNamespace>;
260
+ export type TinaField<WithNamespace extends boolean = false> = Field<WithNamespace> & MaybeNamespace<WithNamespace>;
261
+ type MaybeNamespace<WithNamespace extends boolean = false> = WithNamespace extends true ? {
262
+ namespace: string[];
263
+ } : {};
264
+ export type Template<WithNamespace extends boolean = false> = {
265
+ label?: string | boolean;
266
+ name: string;
267
+ nameOverride?: string;
268
+ ui?: {
269
+ /**
270
+ * Override the properties passed to the field
271
+ * component. This is mostly useful for controlling
272
+ * the display value via callback on `itemProps.label`
273
+ */
274
+ itemProps?(item: Record<string, any>): {
275
+ key?: string;
276
+ /**
277
+ * Control the display value when object
278
+ * items are shown in a compact list, eg:
279
+ *
280
+ * ```ts
281
+ * itemProps: (values) => ({
282
+ * label: values?.title || 'Showcase Item',
283
+ * }),
284
+ * ```
285
+ */
286
+ label?: string | boolean;
287
+ };
288
+ defaultItem?: DefaultItem<Record<string, any>>;
289
+ /**
290
+ * When used in relation to the `visualSelector`,
291
+ * provide an image URL to be used as the preview
292
+ * in the blocks selector menu
293
+ */
294
+ previewSrc?: string;
295
+ };
296
+ fields: Field<WithNamespace>[];
297
+ } & MaybeNamespace<WithNamespace>;
298
+ type TokenObject = {
299
+ id_token: string;
300
+ access_token?: string;
301
+ refresh_token?: string;
302
+ };
303
+ export type LoginStrategy = 'UsernamePassword' | 'Redirect' | 'LoginScreen';
304
+ export type LoginScreenProps = {
305
+ handleAuthenticate: (props?: Record<string, string>) => Promise<void>;
306
+ };
307
+ export interface AuthProvider {
308
+ /**
309
+ * Used for getting the token from the custom auth provider
310
+ *
311
+ * @returns {Promise<TokenObject | null>}
312
+ **/
313
+ getToken: () => Promise<TokenObject | null>;
314
+ /**
315
+ * Used to logout from the custom auth provider
316
+ *
317
+ **/
318
+ logout: () => Promise<void>;
319
+ /**
320
+ * Used for getting the user from the custom auth provider. If this returns a truthy value, the user will be logged in and the CMS will be enabled.
321
+ *
322
+ * If this returns a falsy value, the user will be logged out and the CMS will be disabled.
323
+ *
324
+ **/
325
+ getUser: () => Promise<any | null | boolean>;
326
+ /**
327
+ * Used to authorize the user with the custom auth provider.
328
+ *
329
+ * If this returns a truthy value, the user will be logged in and the CMS will be enabled.
330
+ *
331
+ * If not provided, the existence of a user will be enough to authorize the user.
332
+ *
333
+ * @param context
334
+ */
335
+ authorize: (context?: any) => Promise<any | null>;
336
+ /**
337
+ * Used to authenticate the user with the custom auth provider. This is called when the user clicks the login button.
338
+ *
339
+ **/
340
+ authenticate: (props?: Record<string, any>) => Promise<any | null>;
341
+ fetchWithToken: (input: RequestInfo, init?: RequestInit) => Promise<Response>;
342
+ isAuthorized: (context?: any) => Promise<boolean>;
343
+ isAuthenticated: () => Promise<boolean>;
344
+ getLoginStrategy: () => LoginStrategy;
345
+ getLoginScreen: () => FC<LoginScreenProps> | null;
346
+ getSessionProvider: () => FC<{
347
+ basePath?: string;
348
+ children?: React.ReactNode;
349
+ }>;
350
+ }
351
+ interface AuthHooks {
352
+ onLogin?: (args: {
353
+ token: TokenObject;
354
+ }) => Promise<void>;
355
+ onLogout?: () => Promise<void>;
356
+ }
357
+ type AuthOptions = AuthHooks & AuthProvider;
358
+ export interface Config<CMSCallback = undefined, FormifyCallback = undefined, DocumentCreatorCallback = undefined, Store = undefined, SearchClient = undefined> {
359
+ contentApiUrlOverride?: string;
360
+ authProvider?: AuthProvider;
361
+ admin?: {
362
+ /**
363
+ * @deprecated use `authProvider`and admin.authHooks instead
364
+ */
365
+ auth?: AuthOptions;
366
+ /**
367
+ * Hook functions that can be used to run logic when certain events happen
368
+ */
369
+ authHooks?: AuthHooks;
370
+ };
371
+ /**
372
+ * The Schema is used to define the shape of the content.
373
+ *
374
+ * https://tina.io/docs/reference/schema/
375
+ */
376
+ schema: Schema;
377
+ /**
378
+ * The base branch to pull content from.
379
+ *
380
+ * Note: This is ignored and not needed for local development or when self-hosting
381
+ */
382
+ branch?: string | null;
383
+ /**
384
+ * Your clientId from app.tina.io
385
+ *
386
+ * Note: This is ignored and not needed for local development or when self-hosting
387
+ */
388
+ clientId?: string | null;
389
+ /**
390
+ * Your read only token from app.tina.io
391
+ *
392
+ * Note: This is ignored and not needed for local development or when self-hosting
393
+ */
394
+ token?: string | null;
395
+ ui?: {
396
+ /**
397
+ * When using Tina Cloud's branching feature, provide the URL for your given branch
398
+ *
399
+ * Eg. If you're deplying to Vercel, and your repo name is 'my-app',
400
+ * Vercel's preview URL would be based on the branch:
401
+ *
402
+ * ```js
403
+ * previewUrl: (context) => {
404
+ * const repoName = 'my-app'
405
+ * // `https://<project-name>-git-<branch-name>.vercel.app`
406
+ * return { url: `https://my-app-git-${context.branch}` }
407
+ * }
408
+ * ```
409
+ * [more info](https://vercel.com/docs/concepts/deployments/generated-urls#url-with-git-branch)
410
+ */
411
+ previewUrl: (context: {
412
+ branch: string;
413
+ }) => {
414
+ url: string;
415
+ };
416
+ };
417
+ /**
418
+ * Configurations for the autogenerated GraphQL HTTP client
419
+ */
420
+ client?: {
421
+ /**
422
+ * Skip building the autogenerated client
423
+ */
424
+ skip?: boolean;
425
+ /**
426
+ * Autogenerated queries will traverse references to a given depth
427
+ * @default 2
428
+ */
429
+ referenceDepth?: number;
430
+ /**
431
+ * Determines how the client will handle errors. If it is set to `throw` the client will throw an error when a query fails. If it is set to `include` the client will return the error in the response.
432
+ *
433
+ * @default 'throw'
434
+ */
435
+ errorPolicy?: 'throw' | 'include';
436
+ };
437
+ /**
438
+ *
439
+ * Tina supports serving content from a separate Git repo. To enable this during local development, point
440
+ * this config at the root of the content repo.
441
+ *
442
+ * NOTE: Relative paths are fine to use here, but you should use an environment variable for this, as each developer on your team may have a different
443
+ * location to the path.
444
+ *
445
+ * ```ts
446
+ * localContentPath: process.env.REMOTE_ROOT_PATH // eg. '../../my-content-repo'
447
+ * ```
448
+ */
449
+ localContentPath?: string;
450
+ /**
451
+ * Tina is compiled as a single-page app and placed in the public directory
452
+ * of your application.
453
+ */
454
+ build: {
455
+ /**
456
+ * The folder where your application stores assets, eg. `"public"`
457
+ */
458
+ publicFolder: string;
459
+ /**
460
+ * The value specified here will determine the path when visiting the TinaCMS dashboard.
461
+ *
462
+ * Eg. `"admin"` will be viewable at `[your-development-url]/admin/index.html`
463
+ *
464
+ * Note that for most framworks you can omit the `index.html` portion, for Next.js see the [rewrites section](https://nextjs.org/docs/api-reference/next.config.js/rewrites)
465
+ */
466
+ outputFolder: string;
467
+ /**
468
+ * The host option for the vite config. This is useful when trying to run tinacms dev in a docker container.
469
+ *
470
+ * See https://vitejs.dev/config/server-options.html#server-host for more details
471
+ */
472
+ host?: string | boolean;
473
+ /**
474
+ * If your site will be served at a sub-path like `my-domain.com/my-site`, provide `"my-site"`
475
+ */
476
+ basePath?: string;
477
+ };
478
+ media?: {
479
+ /**
480
+ * Load a media store like Cloudinary
481
+ *
482
+ * ```ts
483
+ * loadCustomStore = async () => {
484
+ * const pack = await import("next-tinacms-cloudinary");
485
+ * return pack.TinaCloudCloudinaryMediaStore;
486
+ * }
487
+ * ```
488
+ */
489
+ loadCustomStore: () => Promise<Store>;
490
+ tina?: never;
491
+ accept?: string | string[];
492
+ } | {
493
+ /**
494
+ * Use Git-backed assets for media, these values will
495
+ * [Learn more](https://tina.io/docs/reference/media/repo-based/)
496
+ */
497
+ tina: {
498
+ /**
499
+ * The folder where your application stores assets, eg. `"public"`
500
+ */
501
+ publicFolder: string;
502
+ /**
503
+ * The root folder for media managed by Tina. For example, `"uploads"`
504
+ * would store content in `"<my-public-folder>/uploads"`
505
+ */
506
+ mediaRoot: string;
507
+ /**
508
+ * Indicates that media files cannot be uploaded or removed by editors
509
+ */
510
+ static?: boolean;
511
+ };
512
+ loadCustomStore?: never;
513
+ accept?: string | string[];
514
+ };
515
+ search?: ({
516
+ /**
517
+ * An instance of a search client like Algolia
518
+ */
519
+ searchClient: SearchClient;
520
+ tina?: never;
521
+ } | {
522
+ searchClient?: never;
523
+ /**
524
+ * Use the Tina Cloud search index
525
+ */
526
+ tina: {
527
+ /**
528
+ * Search index token with permissions to write to search index. Only used by CLI.
529
+ */
530
+ indexerToken?: string;
531
+ /**
532
+ * stopword languages to use (default: eng)
533
+ */
534
+ stopwordLanguages?: string[];
535
+ /**
536
+ * regex used for splitting tokens (default: /[\p{L}\d_]+/)
537
+ */
538
+ tokenSplitRegex?: string;
539
+ };
540
+ }) & {
541
+ /**
542
+ * The number of documents to index per PUT request
543
+ */
544
+ indexBatchSize?: number;
545
+ /**
546
+ * The maximum length of a string field that will be indexed for search
547
+ */
548
+ maxSearchIndexFieldLength?: number;
549
+ };
550
+ /**
551
+ * Used to override the default Tina Cloud API URL
552
+ *
553
+ * [mostly for internal use only]
554
+ */
555
+ tinaioConfig?: {
556
+ assetsApiUrlOverride?: string;
557
+ frontendUrlOverride?: string;
558
+ identityApiUrlOverride?: string;
559
+ contentApiUrlOverride?: string;
560
+ };
561
+ cmsCallback?: CMSCallback;
562
+ formifyCallback?: FormifyCallback;
563
+ documentCreatorCallback?: DocumentCreatorCallback;
564
+ }
565
+ export type TinaCMSConfig<CMSCallback = undefined, FormifyCallback = undefined, DocumentCreatorCallback = undefined, Store = undefined> = Config<CMSCallback, FormifyCallback, DocumentCreatorCallback, Store>;
566
+ export interface Schema<WithNamespace extends boolean = false> {
567
+ /**
568
+ * Collections represent a type of content (EX, blog post, page, author, etc). We recommend using singular naming in a collection (Ex: use post and not posts).
569
+ *
570
+ * https://tina.io/docs/reference/collections/
571
+ */
572
+ collections: Collection<WithNamespace>[];
573
+ /**
574
+ * @deprecated use `defineConfig` in a config.{js,ts} file instead
575
+ */
576
+ config?: Config;
577
+ }
578
+ export type Collection<WithNamespace extends boolean = false> = FieldCollection<WithNamespace> | TemplateCollection<WithNamespace>;
579
+ interface BaseCollection {
580
+ label?: string;
581
+ name: string;
582
+ path: string;
583
+ indexes?: IndexType[];
584
+ format?: 'json' | 'md' | 'markdown' | 'mdx' | 'yaml' | 'yml' | 'toml';
585
+ ui?: UICollection;
586
+ /**
587
+ * @deprecated - use `ui.defaultItem` on the each `template` instead
588
+ */
589
+ defaultItem?: DefaultItem<Record<string, any>>;
590
+ /**
591
+ * This format will be used to parse the markdown frontmatter
592
+ */
593
+ frontmatterFormat?: 'yaml' | 'toml' | 'json';
594
+ /**
595
+ * The delimiters used to parse the frontmatter.
596
+ */
597
+ frontmatterDelimiters?: [string, string] | string;
598
+ match?: {
599
+ include?: string;
600
+ exclude?: string;
601
+ };
602
+ isDetached?: boolean;
603
+ isAuthCollection?: boolean;
604
+ }
605
+ type TemplateCollection<WithNamespace extends boolean = false> = {
606
+ /**
607
+ * In most cases, just using fields is enough, however templates can be used when there are multiple variants of the same collection or object. For example in a "page" collection there might be a need for a marketing page template and a content page template, both under the collection "page".
608
+ *
609
+ * https://tina.io/docs/reference/templates/
610
+ */
611
+ templates: Template<WithNamespace>[];
612
+ fields?: undefined;
613
+ } & BaseCollection & MaybeNamespace<WithNamespace>;
614
+ type FieldCollection<WithNamespace extends boolean = false> = {
615
+ /**
616
+ * Fields define the shape of the content and the user input.
617
+ *
618
+ * https://tina.io/docs/reference/fields/
619
+ */
620
+ fields: TinaField<WithNamespace>[];
621
+ templates?: undefined;
622
+ } & BaseCollection & MaybeNamespace<WithNamespace>;
623
+ type Document = {
624
+ _sys: {
625
+ title?: string;
626
+ template: string;
627
+ breadcrumbs: string[];
628
+ path: string;
629
+ basename: string;
630
+ relativePath: string;
631
+ filename: string;
632
+ extension: string;
633
+ };
634
+ };
635
+ export interface UICollection<Form = any, CMS = any, TinaForm = any> {
636
+ /**
637
+ * Customize the way filenames are generated during content creation
638
+ */
639
+ filename?: {
640
+ /**
641
+ * A callback which receives form values as an argument. The return value
642
+ * here will be used as the filename (the extension is not necessary)
643
+ *
644
+ * eg:
645
+ * ```ts
646
+ * slugify: (values) => values.title.toLowerCase().split(" ").join("-")
647
+ * ```
648
+ */
649
+ slugify?: (values: Record<string, any>, meta: {
650
+ collection: Collection;
651
+ template: Template;
652
+ }) => string;
653
+ /**
654
+ * When set to `true`, editors won't be able to modify the filename
655
+ */
656
+ readonly?: boolean;
657
+ /**
658
+ * When set to `true`, the filename will be shown first in the form
659
+ * @default false
660
+ */
661
+ showFirst?: boolean;
662
+ /**
663
+ * Sets the description for the filename field
664
+ */
665
+ description?: string;
666
+ };
667
+ /**
668
+ * Determines whether or not this collection can accept new docments
669
+ * or allow documents to be deleted from the CMS.
670
+ */
671
+ allowedActions?: {
672
+ create?: boolean;
673
+ delete?: boolean;
674
+ createNestedFolder?: boolean;
675
+ };
676
+ /**
677
+ * Forms for this collection will be editable from the global sidebar rather than the form panel
678
+ */
679
+ global?: boolean | {
680
+ icon?: any;
681
+ layout: 'fullscreen' | 'popup';
682
+ };
683
+ /**
684
+ * Provide the path that your document is viewable on your site
685
+ *
686
+ * eg:
687
+ * ```ts
688
+ * router: ({ document }) => {
689
+ * return `blog-posts/${document._sys.filename}`;
690
+ * }
691
+ * ```
692
+ */
693
+ router?: (args: {
694
+ document: Document;
695
+ collection: Collection<true>;
696
+ }) => Promise<string | undefined> | string | undefined;
697
+ /**
698
+ * This function is called before a document is created or updated. It can be used to modify the values that are saved to the CMS. It can also be used to perform side effects such as sending a notification or triggering a build.
699
+ *
700
+ * @example
701
+ *
702
+ *
703
+ *```js
704
+ * beforeSubmit: async ({ values }) => {
705
+ * return {
706
+ * ...values,
707
+ * lastUpdated: new Date().toISOString(),
708
+ * };
709
+ * },
710
+ *```
711
+ *
712
+ *
713
+ *
714
+ */
715
+ beforeSubmit?: (arg: {
716
+ values: Record<string, unknown>;
717
+ cms: CMS;
718
+ form: TinaForm;
719
+ }) => Promise<void | Record<string, unknown>>;
720
+ }
721
+ export type DefaultItem<ReturnType> = ReturnType | (() => ReturnType);
722
+ type IndexType = {
723
+ name: string;
724
+ fields: {
725
+ name: string;
726
+ }[];
727
+ };
728
+ export type Option = string | {
729
+ label?: string;
730
+ icon?: FC;
731
+ value: string;
732
+ };
733
+ export type UITemplate = {
734
+ /**
735
+ * Override the properties passed to the field
736
+ * component. This is mostly useful for controlling
737
+ * the display value via callback on `itemProps.label`
738
+ */
739
+ itemProps?(item: Record<string, any>): {
740
+ key?: string;
741
+ /**
742
+ * Control the display value when object
743
+ * items are shown in a compact list, eg:
744
+ *
745
+ * ```ts
746
+ * itemProps: (values) => ({
747
+ * label: values?.title || 'Showcase Item',
748
+ * }),
749
+ * ```
750
+ */
751
+ label?: string | boolean;
752
+ };
753
+ defaultItem?: DefaultItem<Record<string, any>>;
754
+ /**
755
+ * When used in relation to the `visualSelector`,
756
+ * provide an image URL to be used as the preview
757
+ * in the blocks selector menu
758
+ */
759
+ previewSrc?: string;
760
+ };
761
+ export type CollectionTemplateableUnion = {
762
+ namespace: string[];
763
+ type: 'union';
764
+ templates: Template<true>[];
765
+ };
766
+ export type CollectionTemplateableObject = {
767
+ namespace: string[];
768
+ type: 'object';
769
+ visualSelector?: boolean;
770
+ ui?: UIField<any, any> & {
771
+ itemProps?(item: Record<string, any>): {
772
+ key?: string;
773
+ label?: string | boolean;
774
+ };
775
+ defaultItem?: DefaultItem<Record<string, any>>;
776
+ };
777
+ required?: false;
778
+ template: Template<true>;
779
+ };
780
+ export type CollectionTemplateable = CollectionTemplateableUnion | CollectionTemplateableObject;
781
+ export type Collectable = Pick<Collection<true>, 'namespace' | 'templates' | 'fields' | 'name'> & {
782
+ label?: string | boolean;
783
+ };
784
+ /**
785
+ * @deprecated use Config instead
786
+ */
787
+ export type TinaCloudSchemaConfig<DeleteMe = undefined> = Config;
788
+ /** @deprecated use Schema instead */
789
+ export type TinaCloudSchema<WithNamespace extends boolean = false> = Schema<WithNamespace>;
790
+ /** @deprecated use Schema instead */
791
+ export type TinaCloudSchemaBase = TinaCloudSchema;
792
+ /** @deprecated use Schema instead */
793
+ export type TinaCloudSchemaEnriched = TinaCloudSchema<true>;
794
+ /** @deprecated use Schema instead */
795
+ export type TinaCloudSchemaWithNamespace = TinaCloudSchema<true>;
796
+ /** @deprecated use Collection instead */
797
+ export type TinaCloudCollection<WithNamespace extends boolean = false> = Collection<WithNamespace>;
798
+ /** @deprecated use Collection instead */
799
+ export type TinaCloudCollectionBase = TinaCloudCollection;
800
+ /** @deprecated use Collection instead */
801
+ export type TinaCloudCollectionEnriched = TinaCloudCollection<true>;
802
+ /** @deprecated use Template instead */
803
+ export type TinaTemplate = Template;
804
+ /** @deprecated use Template instead */
805
+ export type TinaCloudTemplateBase = Template;
806
+ /** @deprecated use Template instead */
807
+ export type TinaCloudTemplateEnriched = Template<true>;
808
+ /** @deprecated use Collection instead */
809
+ export type CollectionFieldsWithNamespace = FieldCollection<true>;
810
+ /** @deprecated use Collection instead */
811
+ export type CollectionTemplates = TemplateCollection;
812
+ /** @deprecated use Collection instead */
813
+ export type CollectionTemplatesWithNamespace = TemplateCollection<true>;
814
+ /** @deprecated use Template instead */
815
+ export type GlobalTemplate = Template;
816
+ /** @deprecated use TinaField instead */
817
+ export type TinaFieldBase = TinaField;
818
+ /** @deprecated use TinaField instead */
819
+ export type TinaFieldInner = TinaField;
820
+ /** @deprecated use TinaField instead */
821
+ export type TinaFieldEnriched = TinaField<true>;
822
+ /** @deprecated use ObjectField instead */
823
+ export type ObjectType<WithNamespace extends boolean = false> = ObjectField<WithNamespace>;
824
+ /** @deprecated use RichTextField instead */
825
+ export type RichTextType<WithNamespace extends boolean = false> = RichTextField<WithNamespace>;
826
+ /** @deprecated use ReferenceField instead */
827
+ export type ReferenceType<WithNamespace extends boolean = false> = ReferenceField & MaybeNamespace<WithNamespace>;
828
+ /** @deprecated use ReferenceField instead */
829
+ export type ReferenceTypeInner = ReferenceType;
830
+ /** @deprecated use ReferenceField instead */
831
+ export type ReferenceTypeWithNamespace = ReferenceType<true>;
832
+ /** @deprecated use RichTextField instead */
833
+ export type RichTypeWithNamespace = RichTextField<true>;
834
+ /** @deprecated use TinaField instead */
835
+ export type SchemaField<WithNamespace extends boolean = false> = TinaField<WithNamespace>;
836
+ export {};